I am using the background services and it does not run on some devices as I have to enable the autostart permission for the app. I want to enable the autostart permission automatically where it needs. I am using this code but it redirects me on the window where the autostart permission is.
Note :-- What I want , Not to redirect the user on the settings screen.
Here is my code for xiaomi
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
//this will open auto start screen where user can enable permission for your app
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent1);
}
Thanks !
Related
I was wondering if there is a way to deep-link to app`s specific settings when asking for permission.
For example, I do the following to ask the user to grant accessibility permission.
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(intent);
The issue is that(And this is the case on Samsung S10 for example) That this takes me to general Accessibility page, after this the user still need to tap on installed Services button and then they need to find and tap on my application and only then they can grant the accessibility permission.
I was wondering if there is a way to shorten this and take them directly to my specific application accessibility granting page.
If you want open directly the settings of your app, you can use the next code:
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "yourPackageName", null);
intent.setData(uri);
startActivity(intent);
I'm not able to start activity in MIUI 11 redmi note 6 pro mobile, I am getting error as:
com.android.server.am.ExtraActivityManagerService: MIUILOG- Permission Denied Activity
I found some solution like turn on "start in background" permission. I can't find something like this with MIUI 11. Literally I have no idea about this issue. Thanks in advance.
I have a similar problem with starting activity from BroadcastReceiver when application is stopped.
1) You can find your app in the settings and allow permission "start in the background".
2) If you need to allow permission programmatically, try to open application settings
Xiaomi
This code will open applicatin permissions settings in which you should allow "start in the background"
Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter",
"com.miui.permcenter.permissions.PermissionsEditorActivity");
intent.putExtra("extra_pkgname", getPackageName());
startActivity(intent);
Devices without system wrappers
This code will open the applicatin settings in which you should open permissions and allow "start in the background" permission
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Read more about android settings intents:
How to open application permission window in app settings programmatically
And you can also check the code from github to work with permissions in different system wrappers like flyme, miui, oppo etc:
https://github.com/zhaozepeng/FloatWindowPermission
Hope this helps you!
If you have other options for resolving this issue, I would appreciate a reply in the comments . . .
I want my app to be in the autostart list and in running state after installation.
I know when I install an app like (WhatsApp) it goes automatically to the autostart list. I want my app to be the same
some app always listed under the running state like show above I want my app to be the same
I try this code for autostart
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);'
it's work but it will throw to autostart manager where I manually found the app and allow autostart. also, I try a lot but don't get any possible solution for put application into the running state like shown into the image.
When my online radio application goes in doze mode there is no network access because of which the radio stops working.Even the wake locks don't work in doze mode.
I've added the intent as per qouted in documentation.
An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can
trigger a system dialog to let the user add the app to the whitelist
directly, without going to settings. The app fires a
ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the
dialog.
Here is the intent.
Intent myIntent = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
myIntent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
myIntent.setData(Uri.parse("package:" + getPackageName()));
startActivity(myIntent);
}
also i have added permission in manifest because the intent is not working without it.
Is it safe to use this permission in a radio application?
I am building an android application where I am using some services. My services get close when application is close in some custom android OS like MI.
Then I figure out we have to push our application in white list of security autostart application.
I got some SOF link's where they are suggesting below answer.
String manufacturer = "xiaomi";
if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
//this will open auto start screen where user can enable permission for your app
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
}
This above code used to send user to that particular page.
Now I have to check if my application is disable so I can send user to this page and if it is enable then move to other screen. Is there any way to check this?
There is no Android API to check if the the AutoStart is enabled or not. Though you can have your own logic in the App (may be you can use preference to set a Boolean for it) to check this. Also the above way to enabling the AutoStart might not work always. Please have a look here