Search code examples
androidandroid-studioandroid-permissionsxiaomimiui

Could not start activity from service (com.android.server.am.ExtraActivityManagerService: MIUILOG- Permission Denied Activity)


Device: Xiaomi Redmi 4A, Android 7, MIUI 10.

Code for running activity from service:

String pkgName = context.getPackageName();
Intent intent = new Intent(context, main_activity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
intent.setPackage(pkgName);
intent.setComponent(new ComponentName(pkgName, main_activity.class.getName()));
startActivity(intent);

does not do anything. In logcat there are following messages:

11-25 23:56:57.697 10012 10094 I Timeline: Timeline: 
Activity_launch_request time:191155603 intent:Intent { 
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] 
flg=0x10100000 pkg=com.qwe7002.telegram_sms cmp=com.qwe7002.telegram_sms/.main_activity }
11-25 23:56:57.699  1416  7227 I ActivityManager: 
START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] 
flg=0x10100000 pkg=com.qwe7002.telegram_sms cmp=com.qwe7002.telegram_sms/.main_activity} 
from uid 10340 on display 0
11-25 23:56:57.699  1416  7227 
D com.android.server.am.ExtraActivityManagerService: MIUILOG- Permission Denied Activity : Intent { 
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 
pkg=com.qwe7002.telegram_sms cmp=com.qwe7002.telegram_sms/.main_activity } 
pkg : com.qwe7002.telegram_sms uid : 10340 tuid : 10020

Solution

  • Solution that helped to me:

    • Building apk in release version, not in debug version.

    As turned out MIUI blocks starting activities from service for debug applications.

    There are recommendations ( Just turn on the "Start in background" permission, Manually enable background pop-up permission ) to give to the app Start in foreground, Display pop-up window permissions. But this does not change anything in my case.


    Related questions: