https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
https://medium.com/react-native-development/fixing-problems-in-react-native-caused-by-new-permission-model-on-android-1e547f754b8
talks about overlay permission.
They add the permission check code to the activity which hosts react native 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 the permission is required because react native needs to show the debug window in an overlay.
How to turn it off in production build?
I turned it off in release with two changes, one in the manifest, and one in the code.
First: In your main Manifest (src/main/AndroidManifest.xml), remove the line:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Add a new manifest in 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 the permission only on debug variants.
Second, to 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With