MIUI Permission Denied Activity KeyguardLocked

2020-07-11 06:06发布

问题:

When application is in background and screen is locked,I'm unable to start activity, there is no exception or warning, onCreate() is just not called. I've been struggling against this problem for while, and I think I've finally found the source of it. There is a line in logs:

D/com.android.server.am.ExtraActivityManagerService: MIUILOG- Permission Denied Activity KeyguardLocked: Intent { flg=0x14010000 cmp=com.trueconf.videochat/com.trueconf.gui.activities.Call (has extras) } pkg : com.trueconf.videochat uid : 10634

Is this why I can't start an activity? Also, how do I solve this, should I disable keyguard or something?

回答1:

This is a special permission on MIUI that has to be enabled for apps.

You can find it in

  1. Settings
  2. Manage Apps
  3. YOUR APP
  4. Other permissions
  5. Show on Lock screen

User must enable this manually. As far as I know, the best you can do is to guide the user to this settings menu directly by launching an intent (and probably showing some explainer text prior to this).

Intent looks like this

startActivity(new Intent("miui.intent.action.APP_PERM_EDITOR").putExtra("extra_pkgname", getPackageName()))

Make sure to try catch it as it can throw exceptions if activity can't be started (e.g. the device actually is not running MIUI or the intent is somehow not valid on the particular device/version)