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.
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'm facing the known issue onActivityResult getting called immediately.
I read the reason behind it on some link
where it is advice to change launch mode of called activity.
But in my case I'm starting(navigating to) settings activity, to let the user enable data connection.
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS),
Constants.REQUEST_ENABLE_DATA_CONNECTION);
So I can't change launch mode of Settings activity.
I tried setting some flags to Intent e.g. intent.setFlags(0); but its not working.
I think there is some problem with your request code "Constants.REQUEST_ENABLE_DATA_CONNECTION".What is your request code value.
I think you should use zero "0" value like this.
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
but if you need to open wifi settings then use this code.
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
and see this Setting actions link for other setting actions.
I hope,this will help you.
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 have an air for android app that has event listeners for ACTIVATE and DEACTIVATE, inside the activate I tell the screen to stay awake and in the deactivate I tell it to go back to normal like so :
stage.addEventListener(Event.DEACTIVATE, deactivateHandler);
stage.addEventListener(Event.ACTIVATE, activateHandler);
protected function deactivateHandler(event:Event):void{
SFX.disableSound();
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
protected function activateHandler(event:Event):void{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
But the screen will stay awake at all times even when on the android home screen unless you force close the app... any ideas?
Thanks
I had this exact problem. My app was able to keep the screen on by setting systemIdleMode to SystemIdleMode.KEEP_AWAKE, and it would force the screen to stay on. However, when the app tried to set the systemIdleMode back to SystemIdleMode.NORMAL, so the screen could turn off, the screen was still staying on.
What turned out to be the problem in my case is was a missing android permission. I had already added this permission to my app XML file, so that i could use the keep-alive function:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Turns out this is not the only permission you need. I added this permission also:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
And suddenly my app was able to let the screen be turned off again.
You could try using this in your java code:
// Gets one of the views visible on the screen and sets keepScreenOn to true.
// This means the screen will stay on as long as the specified view is visible.
this.findViewById(R.id.viewId).setKeepScreenOn(true);
Or you could put android:keepScreenOn="true" in your layout.
I want to open the Settings-> Sound & Display-> Phone Ringtones screen from my application. How can I do that?
Depending on your needs, there are a couple of alternatives to bring up the 'Ringtones' settings screen from your application.
If you want to bring up the actual preferences screen that is usually available through system settings -- letting your user modify the phone's universal ringtone settings through your application -- you can use the ACTION_SOUND_SETTINGS constant from the android.provider.Settings class to create a new Intent to start the sound settings activity.
startActivityForResult(new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS), 0);
If you want to select a custom ringtone to use in your application you need to add a RingtonePreference in your preferences.xml definition file, like this:
<RingtonePreference
android:key="alerts_ringtone"
android:title="Select ringtone"
android:showDefault="true"
android:showSilent="true"
android:ringtoneType=""
/>
You'll be able to get the URI to the selected preference in the application's default SharedPreferences using alerts_ringtone as the key.
The latter technique uses the PreferenceActivity class to host the preference options. I won't describe that in detail here, as the Android documentation has a good writeup and some sample code.
This is an alternate solution for the problem. I am also working in the same task but the above code does not work for me. I have changed the code to
startActivityForResult(new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS), 0);
and it now works.