How to disable overlay permission on Android
https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
talks about overlay resolution.
They add permission checking code to an activity where hosts respond to their own view.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
}
It seems like permission is required because react native needs to show debug window in overlay.
How can I disable it when creating an assembly?
+3
source to share
1 answer
I turned it off in a release with two changes, one in the manifest and one in the code.
First: in the main manifest (src / main / AndroidManifest.xml) remove the line:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Add a new manifest to src / debug / AndroidManifest.xml that looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mycompany.myapp">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
</manifest>
This will merge permission only in debug options.
Second, in the code you mentioned, I added a check for BuildConfig.DEBUG:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this) && BuildConfig.DEBUG) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
}
+1
source to share