Sven Bläse
Mar 31, 2017
2:38 pm

Permit drawing over other apps

Hello everybody,

I am currently trying to grant permission to an app to "Permit drawing over other apps" without the user having to manually select that option in settings. I already tried to grant runtime permission "android.permission.SYSTEM_ALERT_WINDOW" with applyRuntimePermissions(), which does not seem to work.

Is there another way to make this work?

Thank you very much

Sven

Similar topics

No similar topics found.
Samuel Veloso
Mar 31, 2017
5:08 pm

Hi Sven,

What device and Android version are you working with?

Samuel

Sven Bläse
Apr 03, 2017
6:31 am

Hi Samuel,

I am using the Samsung Galaxy Tab A 10.1 T585 Tablet with recent updates (Android 6) installed.

Thank you very much

Samuel Veloso
Apr 03, 2017
6:55 pm

Hi Sven,

There is new behavior introduced in Android 6.0.1 where every app that requests the SYSTEM_ALERT_WINDOW permission and is installed through Play Store will grant the permission automatically. But if you're testing your app by building the APK, the permission is not automatically granted. 

Let me know if you have any other questions.

Best regards,

Samuel

Ruslan Yanchyshyn
Mar 19, 2019
2:43 pm

Is there a way to grant "draw over other apps" permission using Knox API?

Sebastian Barthelmess
May 08, 2019
2:00 am

As mentioned here before, looks like Google play applies that directly if you've passed muster in their app store - clearly that is not what you are looking for here.  Several MDM providers have been granted this ability as well (SOTI, Knox Manage, etc...).  This permission requires signature level and the direct Knox APIs are not exposed.

You are on the right track looking into applying the runtime permissions with this Knox API ->  https://seap.samsung.com/api-references/android/reference/com/samsung/an...(com.samsung.android.knox.AppIdentity,%20java.util.List%3Cjava.lang.String%3E,%20int)

 

So for your code something like the following:

 List<String> runtimePermissions = new ArrayList<String>();
 runtimePermissions.add("android.permission.SYSTEM_ALERT_WINDOW");
 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 ApplicationPolicy appPolicy = edm.getApplicationPolicy();
 try {
     boolean ret = appPolicy.applyRuntimePermissions(appIdentity, runtimePermissions, PERMISSION_POLICY_STATE_GRANT);
     if (ret) {
         Log.w(TAG, "Granted runtime permissions " + runtimePermissions + " successfully");
     } else {
         Log.d(TAG, "Failed to grant runtime permissions " + runtimePermissions);
     }

 } catch (SecurityException e) {
     Log.w(TAG, "SecurityException: " + e);
 }

And THEN force the runtime request to be called through standard Android APIs (key piece):

    // Check if Android M or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // Show alert dialog to the user saying a separate permission is needed
        // Launch the settings activity if the user prefers
        Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
        startActivity(myIntent);
    }

There is a great explanation of what is going on and why here: https://stackoverflow.com/questions/36016369/system-alert-window-how-to-... Worst case (on even newer versions of Android) you can force them into a UI loop to accept before continuing with the app. 

In case you find yourself at a dead end, another [less conventional] trick is to use the RemoteInjection to send the keypress to accept the permission, but this is always a little hacky and may cause visual artifacts.  The API is here https://seap.samsung.com/api-references/android/reference/com/samsung/an....

Hope this helps get you moving in the right direction.

-Sebastian