10

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.

1 Answers1

17

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 . . .

lincollincol
  • 762
  • 2
  • 12
  • 23
  • 2
    Solution is good. Is there any way to grant that permission programatically? I've seen that Facebook did it. Because When I Install app it by default on permission in Facebook app. – Bhavin Chauhan May 13 '20 at 04:39
  • 1
    @BhavinChauhan such apps like Facebook have more privileges by default. Google's policy forces developers to request permissions at runtime with default tools, where the permission of other system wrappers like MIUI is not usually provided. We must describe the intentions of using the function for which we are requesting permission in the dialog and direct the user to the settings. It is also good practice to close the application or limit some of its features if the user has declined the permission offer. – lincollincol May 13 '20 at 07:44
  • 1
    @BhavinChauhan In my application (alarm clock) I used device admin and notifications. check here how to implement device admin -> https://stackoverflow.com/questions/13672404/lock-android-phone or read more about device admin here -> https://developer.android.com/reference/android/app/admin/DeviceAdminReceiver So, I lock screen in my broadcast receiver and then show notification. See my code snippet here -> https://github.com/lincollincol/AlarmClock-for-programmers/blob/master/app/src/main/java/linc/com/alarmclockforprogrammers/infrastructure/service/AlarmReceiver.java – lincollincol May 13 '20 at 07:45
  • 1
    @BhavinChauhan This is not the best practice, but this is another method of solving the problem WITHOUT PERMISSION. – lincollincol May 13 '20 at 07:45
  • 2
    @BhavinChauhan is there any way to know is permission granted or not? – Raj Gohel Jun 17 '20 at 06:30
  • 2
    Because we should not ask for permission if user already grant permission – Raj Gohel Jun 17 '20 at 06:31
  • 1
    @RajGohel Sorry I don't know how to check that permission – Bhavin Chauhan Jun 18 '20 at 04:41
  • 1
    @lincollincol - thank you for this - is there a way in code to heck if the permission is already granted, to open open the dialog if needed? – Yossi Dahan Jul 02 '23 at 21:05