Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIUI 10 doesn't let service start activity - Xiaomi Redmi Note

Tags:

java

android

miui

My app has a service and an activity. From the service, activity is called with following code:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

even without the flags, normally the activity window is displayed with its correct layout. However, on Xiaomi Redmi Note 4 with Android 7, activity layout is not displayed. I only see the following line on logcat:

I/Timeline: Timeline: Activity_launch_request time:281438674 intent:Intent { flg=0x30000000 cmp=com.test.app/.MainActivity }

I believe this is not an Android 7 (API 24) issue because on another device with Android 7, service can successfully start the activity. I guess, MIUI is preventing the launch of the activity from service.

I tried changing how the activity was defined in the manifest. I also tried with several different flags. All of my tests failed. I could not succeed in starting the activity. Worst issue is that there is no error/exception in the logs.

Any ideas on this please ?

like image 641
ilker Aktuna Avatar asked Dec 08 '19 19:12

ilker Aktuna


People also ask

Why apps are not opening in redmi?

If it is coming blank or neither Uninstall nor Update option is appearing, then go to Settings>System Apps > Manage Apps, search for Google Playstore and clear the cache. 4. Now, your phone should start working flawlessly without any crash.

How do I stop Miui from killing apps?

Please enable: Settings > Advanced Settings > Battery manager > Power plan is set to Performance. Device Settings > Advanced Settings > Battery Manager > Protected apps – your app needs to be Protected. Device Settings > Apps > your app > Battery > Power-intensive prompt and Keep running after screen off.


1 Answers

In App Info screen from the system Settings app > Other permissions > Display pop-up windows while running in the background.

This seems introduced in MIUI 11.

Edit: here is a piece of code that I use. I add that into a permission list in a RecyclerView.

Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
String miui = (String) get.invoke(c, "ro.miui.ui.version.name");
if (miui != null && miui.contains("11")) {
            PermissionData mPopup = new PermissionData();
            mPopup.text = "Other permissions > Display pop-up while in background";
            mPopup.onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", getPackageName(), null);
                    intent.setData(uri);
                    startActivity(intent);
                }
            };

            mPermissionData.add(mPopup);
}

UPDATE: To check if this permission is granted you could use an already running service and launch a dummy transparent activity, and in the onCreate call back on a LocalBroadcastManager or similar and you'll know it's granted. It's an ugly solution, but it may be useful for some.

like image 55
Alex Newman Avatar answered Oct 22 '22 21:10

Alex Newman