I am creating an application in Android for which I need to be able to enable or disable programmatically, the audible selection option that we see in the Sound and DIsplay settings.
I am not able to find the API for this. Please help me with it.
from https://github.com/CyanogenMod/android_packages_apps_Settings/blob/ics/src/com/android/settings/SoundSettings.java
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.loadSoundEffects();
Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED,1);
Related
I will get " An app requesting permission to use WLAN. Allow?" prompt window in real mobile phone Samsung SM-J5008 with Android 5.1 when I try to change status of WiFi.
I have google some information ,such as https://groups.google.com/d/msg/tasker/C5ZgPA2J7aM/bH7j85buAAAJ
A dialog box "Ask to use WLAN" will be displayed, and require me to choice whether to display the dialog box when I try to change the status of WiFi.
I hope to set "Ask to use WLAN" dialog box off programmatically , so the dialog will not be displayed when I change WiFi status, how can I do? Thanks!
Image
Added Content
I set the status of WiFi using the following code.
fun setWiFi(aWiFiDef: WiFiDef){
val wifiManager =mContext.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
wifiManager.isWifiEnabled=aWiFiDef.status
}
Use the below code to switch WiFi ON or OFF. Make sure you have added the <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> PERMISSION and also note that you might need to replace "this" by your activity's current context.
WifiManager wifiManager = (WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()){ // Is ON , switch it OFF
wifiManager.setWifiEnabled(false);
}else{ // Is OFF, switch it ON
wifiManager.setWifiEnabled(true);
}
Using this code i am able to switch the WiFi adapter ON and OFF with no additional dialog prompt.
Here is the documentation taken from developer.android.com :
Make sure that you only try to change the WiFi status using the above code and that there isn't any piece of code elsewhere in your activity trying to accomplish the same thing. There might be a listener in your code that detects your intent to change the WiFi status (switch it ON or OFF) and displays the dialog you've shown us.Find it and remove it.
If after those changes the dialog is still being displayed, then as #VicJordan said, it might be an OEM implementation issue in which case i am sorry but i cannot help you.
Best of luck!
I think you can do it by adding CHANGE_WIFI_STATE permission to your manifest file.
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
CHANGE_WIFI_STATE is a normal permission so maybe that "Ask to use WLAN" popup can be skipped. I am saying maybe because it depends upon OEM's customization, how they are handling this "Ask to use WLAN" popup.
Hope this helps.
I have a HTC one M8 running Android 5. I have gone into settings -> more -> data usage -> restrict background data (checked)
This should turn background data off.
I would like to turn it back on (uncheck the checkbox) programmatically with the following code in onCreate of one of my Activities.
ContentResolver.setMasterSyncAutomatically(true);
.
Unfortunately it doesn't turn back on. I have the following in the manifest
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
Are there any ideas why this isn't working?
thanks in advance
Does any body know how to enable pointer location options on by java code?
Settings > Developer Options > Pointer Location
and toggle that on
Add this permission to your manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
then import this to your class:
import android.provider.Settings;
and write settings like this:
Settings.System.putInt(getActivity().getContentResolver(),
"show_touches", 1);
Settings.System.putInt(getActivity().getContentResolver(),
"pointer_location", 1);
First off, not all devices may have the Developer Options unlocked (as they are hidden by default).
Now, it is not possible to stealthily enable Pointer Location input programmatically, but you can show the user the respective Setting screen by including:
context.startActivity(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
where they can enable/disable it.
I want to enable animations in my app, I am doing this but to no effect.
Settings.System.putInt(getContentResolver(), Settings.System.WINDOW_ANIMATION_SCALE, 1);
Settings.System.putInt(getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE, 1);
I have given permssion in manifest too,
uses-permission android:name="android.permission.WRITE_SETTINGS"
Please advise,
It may be that the settings won't work until you finish and then re-create the activity. I know this is the case for changing localisation settings and may be the same for the settings you are trying to set?
Also, just for debugging purposes, you could call Settings.System.getInt after putInt to check the system is actually storing the correct settings value.
I google this and there is a lot of examples in handling the even on_screen_of and on_screen_off, but I want to actually turn on and turn off the screen. Every search I made it lead me on handling the screen on and off event.
I want to have a button that when clicked will turn the screen off.
How can I do this, and what permissions do I need ? or I this is talked before please give me some useful link
Thanks
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(int amountOfTime);
You will probably need this permission too:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Answer extracted from here