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

后端 未结 1 1971
陌清茗
陌清茗 2020-12-08 15:50

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

Intent intent = new Intent(getApplicationContext(), MainActi         


        
1条回答
  •  抹茶落季
    2020-12-08 16:23

    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.

    0 讨论(0)
提交回复
热议问题