My android application requests permission for accessibility. On older versions of android, the code below opens the
correct accessibility permission screen. But testing on a samsung with android 12, it doesn't work.
private void launchPermission() {
AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
startActivity(intent);
}
Can you help me to solve this problem?
Related
I have an app that uses BLE to exchange data with a BLE-capable device.
I used to develop and test it using Asus Zenfone Max 3 (Android 8.1) and I had no problems.
Then, I got an Asus Zenfone Max Pro M1 (Android 8.1). The app connects to the device but could not exchange any data.
After long investigation, it turns out that I had to go to Battery optimization in the smartphone's settings and change Bluetooth and Bluetooth MIDI Service to Not optimized and then my app worked fine.
I don't know whether this default setting is related to the OS (Android One) or to the phone model. But it is really a crappy thing because I am not supposed to tell every customer to do this (in his phone's settings) in order for the app to work !
So, my question is, is their a way to know, from the code, whether these services are optimized or not, and whether I can change these settings by code or any other ideas that could better fix this issue.
Add this permission to your manifest file:
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
and test it like this :
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);
reference
"This Feature is not available on this device" While asking DND permission
How can we check whether the device has DND feature or not or any other solution please..
I am using below code to get DND permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !notificationManager.isNotificationPolicyAccessGranted()) {
Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
}
The device I am using has Oreo and nougat.
This feature doesn't seems to be available on all versions of Oreo. For example on "Oreo Go Edition" on a Wiko Lenny 5, I don't have it either.
Currently using powerManager.isIgnoringBatteryOptimizations(getPackageName()) for devices running api >= 23.
And requesting user to allow my app to be not optimised by using
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName()));
This works on most of the devices, but on Oneplus devices even after user allowing it to be not optimised, I see no effect, my application is still optimised and I miss SMS_RECEIVED broadcast.
Oneplus device with Oxygen OS 5.0.1 and Android OS 8.0.0
I implemented ignore battery optimization functionality programmatically.
I found lots of questions and answers but i want to know that the IGNORE_BATTERY_OPTIMIZATIONS is works only for pure android or is there any other cases?
I have couple of devices as below listed :
Moto g4 (7.0)
Moto g play (6.0)
Samsung galaxy note 4(6.0)
Mi note 4 (6.0)
Lenovo Tab(6.0)
Honor (6.0)
It works proper in Moto device.
In Moto we able to get pop up and if we accept permission then it works well.
It work 50% correct in Lenovo tab & Honor devices.
In Lenovo tab when the Permission pop up appears and if we accept the permission then the application added but when we change settings manually it's not working.
Well while in Honor devices when we got permission popup and accept the permission after that we open setting and check the app status its listed in don't allow battery optimization app but the state of the application is "Allow battery optimization". After that when we allow it manually it will work.
In MI and Samsung devices it's not working anymore.
well The Mi Devices are exceptional cases as they have their customized architecture, so we are not concerning MI devices.
for Samsung note 4 there is a special case as below :
After installing app we got the permission pop up and accept the permission. After that we check it in setting, but the app is not listed in "don't allow battery optimization" app list. (Note: When device will reboot the app added in don't allow battery optimization)
Here is Code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
msPackageName = getPackageName();
moPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
Log.i(TAG, "Permission " + moPowerManager.isIgnoringBatteryOptimizations(msPackageName));
if (!moPowerManager.isIgnoringBatteryOptimizations(msPackageName)) {
Intent loIntent = new Intent();
loIntent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
loIntent.setData(Uri.parse("package:" + msPackageName));
startActivity(loIntent);
}
}
Please advice for this different behavior. and if there is a solution please let me know that. it's becoming frustrating.
As we know, from Android 4.0 users can disable/enable pre-installed system apps.
Intent.ACTION_PACKAGE_CHANGED can be received by register broadcast receiver, but I can NOT distingguish app disable or enable.
My question is how to distingguish them ?
Some sample code:
public void checkEnable() {
PackageManager pm = getPackageManager();
ComponentName cn = new ComponentName("FULL PACKAGENAME", "Full ComponentName(activity/service)");
int ret = pm.getComponentEnabledSetting (cn);
if(ret != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Log.w(TAG, "We are disabled by someone...");
} else {
}
}
So Are you rooted, Unless you are rooted you can't disable a third party app, since your app is also a third party app to the system, Check this link
It contains something useful for you