Android Question Start in Background - xiaomi phone

alirezahassan

Active Member
Licensed User
hi all,
i want to start activity from service.
but xiaomi phone and maybe poco phone have to get 'Start in Background' permission.
Can anyone change the code for me to b4a code?

photo_2021-11-06_19-45-40.jpg
photo_2021-11-06_19-45-32.jpg


I need a sub to get access and a sub to check this access.

This code will open applicatin permissions settings in which you should allow "start in the background"
Java:
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
startActivity(localIntent);
This code will open the applicatin settings in which you should open permissions and allow "start in the background" permission
Java:
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

The following code is not for 'Start in Background' access.
But this access is almost close to the 'Start in Background 'access and with some changes the 'Start in Background' access
Java:
  public static boolean canDrawOverlayViews(Context context)
  {
    if (Build.VERSION.SDK_INT < 21)
      return true;
    try
    {
      return Settings.canDrawOverlays(context); } catch (NoSuchMethodError e) {
    }
    return canDrawOverlaysUsingReflection(context);
  }

  public static boolean isXiaomi()
  {
    return "xiaomi".equalsIgnoreCase(Build.MANUFACTURER);
  }

  private static boolean canDrawOverlaysUsingReflection(Context context)
  {
    try
    {
      AppOpsManager manager = (AppOpsManager)context.getSystemService("appops");

      Class clazz = AppOpsManager.class;
      Method dispatchMethod = clazz.getMethod("checkOp", new Class[] { Integer.TYPE, Integer.TYPE, String.class });
      int mode = ((Integer)dispatchMethod.invoke(manager, new Object[] { Integer.valueOf(24), Integer.valueOf(Binder.getCallingUid()), context.getApplicationContext().getPackageName() })).intValue();

      return mode == 0; } catch (Exception e) {
    }
    return false;
  }
 
Last edited:
Top