My goal is to support a functionality that mute phone (possibly with vibrations enabled/disabled), so when a call or sms is received it won't make noise
unmute phone but prompt for "password for unmute".
And this remains valid for any other application, that it ask for password entry before unmute...
How can I do this? What permissions are required in AndroidManifest?
Previously on Stackoverflow, Android mute/unmute phone.
Those answers discuss both permissions and the coding. Also, tasker can handle everything you're looking to do.
And here's a link to a tutorial.
The code below runs fine in the emulator. When you run it, you can see the mute goes on in the notification area. In addition to the code, I had to add the (uses) permission for android.permission.MODIFY_AUDIO_SETTINGS.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
AudioManager audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
return true;
}
Related
I want to disable copy/paste option of my Entry control in Xamarin forms application. I am using custom renderer for that. The current solution is working in all the other devices apart from Redmi Note 8. This is my renderer code.
class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.CustomSelectionActionModeCallback = new Callback();
Control.CustomInsertionActionModeCallback = new Callback();
Console.WriteLine("CustomSelectionActionModeCallback");
Control.SetTextIsSelectable(false);
Control.LongClickable = false;
}
}
}
public class Callback : Java.Lang.Object, ActionMode.ICallback
{
public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
{
Console.WriteLine("OnActionItemClicked");
return true;
}
public bool OnCreateActionMode(ActionMode mode, IMenu menu)
{
Console.WriteLine("OnCreateActionMode");
menu.Clear();
return false;
}
public void OnDestroyActionMode(ActionMode mode) {
Console.WriteLine("OnDestroyActionMode");
}
public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
{
Console.WriteLine("OnPrepareActionMode");
menu.Clear();
menu.Close();
return true;
}
}
}
So long click is getting disabled in Redmi Note 8 but still there is blue color dot which appears. On click of that it still shows me copy/paste option. It is happening only in Redmi note 8. And in my code no other callback is getting hit other than OnDestroyActionMode and I'm not able to execute menu.Clear. In other devices that option is getting disabled by using this code
Control.SetTextIsSelectable(false);
This is how it is getting shown in Redmi Note 8 device.
I have referred these links because this issue is quite similar to mine but it didn't help.
Disable EditText context menu
EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event
As you can see in the image the paste option is getting shown in the device. I have no clue how to fix this bug any suggestions?
I have found two solutions for this. One is clearing the clipboard and other is setting the variation of input as visible password. Both these solutions serves my purpose. For clearing the clipboard you can use the following code in your renderer
var clipboardManager = (ClipboardManager)Forms.Context.GetSystemService(Context.ClipboardService);
clipboardManager.ClearPrimaryClip();
And for setting the variation of input as visible password you can use the following code
Control.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationVisiblePassword;
So these are the solutions which was useful for me.
I've been developing an app in a Marshmallow 6.0 phone. Today, I ran it in a Nougat 7.0 phone and everything was ok. Changed one line of xml code ('selectableItemBackground' to 'selectableItemBackgroundBorderless' in a LinearLayout) and got an NPE on an unrelated MenuItem ("Attempt to invoke interface method 'android.view.MenuItem android.view.MenuItem.setIcon(int)' on a null object reference") here:
public void updateSpeakerIcon() {
if (mIsSpeakerOn) {
mSpeakerIcon.setIcon(R.drawable.speaker);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
} else {
mSpeakerIcon.setIcon(R.drawable.earphone);
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
}
I'm using a ViewPager; this method is declared in the activity that contains it; the fragments call this method in their onResume callback.
mSpeakerIcon is 'found' in the onCreateOptionsMenu callback, in the same activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.qmenu, menu);
mSpeakerIcon = menu.findItem(R.id.toggle_speaker);
return true;
}
I've changed the one line back to what it was but, of course, it did not fix the problem. Ran the app once again in the 6.0 device and there's no error.
Any ideas? Thanks in advance!
I'm having issues with my prototype application. It works fine between two emulators on my PC, but when I install it on my phone it won't send text messages or even care to ask for the permission (if that is the issue).
Furthermore, I'm recieving the same error no matter what I do, on app start, each time I press a button and on every new intent start:
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
I've been looking at a lot of similar issues, and I did add
uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>
to my manifest, but nothing seems to work for me.
The real odd thing to me is that the error occurs on application start, because nothing interesting really seems like nothing interesting is happening at that point:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Go to contact list
public void onClick(View view) {
Intent i = new Intent(this,AddContact.class);
startActivity(i);
}
public void onGPS(View view) {
Intent j = new Intent(this,GPSActivity.class);
startActivity(j);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Any ideas ?
The issue is seemingly with Samsung Galaxy S3. The link: Permission Denial: this requires android.permission.INTERACT_ACROSS_USERS_FULL
Provided by Sumighosh Chaurvil explains the problem; And that there's really not much to do about it.
I installed the application on another phone, and it works with no problems whatsoever!
I have created a sample Android application just to see the "Google Cast" button on Action Bar and a list of ChromeCast devices when I press it. I did everything according to "Android Sender App Development" document. Now I do see my ChromeCast device when we are on same WiFi, but if I switch on my phone to another WIFi, I don't see my ChromeCast as a "nearby device". I did turned on a flag "Supports Google Cast Guest Mode" on "Google Cast SDK Developer console" for my application. What I am missing?
Here is the code in my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(MY_APP_ID))
.build();
}
#Override
protected void onResume() {
super.onResume();
mMediaRouterCallback = new MyMediaRouterCallback();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
#Override
protected void onPause() {
if (isFinishing())
mMediaRouter.removeCallback(mMediaRouterCallback);
super.onPause();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.cast, menu);
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat
.getActionProvider(mediaRouteMenuItem);
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
return true;
}
It turns out that the guest mode only works if the application is published.
I published my app (code above) and it started to show the ChromeCast button in both WiFi and guest mode.
The Problem
On Android versions < 4.1, the alpha value of the MenuItem is getting reset after an orientation change, BUT it remains disabled.
The code I'm using
DetailsFragment.java
public class DetailsFragment extends SherlockFragment {
private MenuItem miEmail;
...
#Override
public void onPrepareOptionsMenu(Menu menu) {
miEmail= menu.findItem(R.id.menu_email);
super.onPrepareOptionsMenu(menu);
}
private void populateDetails(final Detail oDetail) {
//disable email button if dealer doesn't have option
if(!oDetail.bShowSAM){
miEmail.setEnabled(false);
miEmail.getIcon().setAlpha(50);
}
...
}
}
MyManifest.xml
<activity
android:name=".activities.DetailsActivity"
android:uiOptions="splitActionBarWhenNarrow"
android:configChanges="keyboardHidden|screenSize|orientation">
</activity>
What I expect to happen
When the orientation changes, miEmail is still disabled and the alpha value is still at 50.
What is actually happening
When testing on older devices(2.3,4.0), the MenuItem is remaining disabled but the alpha value is getting reset to the default value. When testing with my devices that are >4.1, it is working as expected.
What I've tried
Googling the problem.......
I've tried to avoid using the android:configChanges="..." and handling the data through savedInstanceState, but I've learned you can't make the MenuItem serializable/parciable, thus not allowing me to pass it through outState bundle object.
I'm fairly new to Android development and I feel as though there is a trivial way of handling this MenuItem, but I cannot figure how else to handle it.
What do you think is the issue?
Any feedback will be greatly appreciated.
Dont set the icon alpha on your custom function, instead, set it on OnPrepareOptionsMenu (with a suitable conditional). You can pass a boolean on savedinstancestate saying whether it should be grayed or not.
In your populateDetails function, you would call invalidateOptionsMenu() to make android remake the action bar icons. Example:
private boolean buttonEnabled;
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem miEmail= menu.findItem(R.id.menu_email);
if (buttonEnabled) {
miEmail.setEnabled(true);
miEmail.getIcon().setAlpha(255);
}else{
miEmail.setEnabled(true);
miEmail.getIcon().setAlpha(50);
}
return super.onPrepareOptionsMenu(menu);
}
private void populateDetails(final Detail oDetail) {
//disable email button if dealer doesn't have option
if(!oDetail.bShowSAM){
buttonEnabled = false;
InvalidateOptionsMenu();
}
...
}
}
If you are using the support library for compatibility, use supportInvalidateOptionsMenu instead.
By the way, never use the orientation tag to "fix" the problem, the issue will still appear if you quit the app for a long time and then try to open it. (android pauses the activity initially and will stop it after a while)