问题描述
https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
谈论覆盖权限.
他们将权限检查代码添加到承载本机视图的活动中.
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);
}
}
似乎需要权限,因为 React Native 需要在叠加层中显示调试窗口.
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.
首先:在您的主清单 (src/main/AndroidManifest.xml) 中,删除以下行:
First: In your main Manifest (src/main/AndroidManifest.xml), remove the line:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
在 src/debug/AndroidManifest.xml 中添加一个看起来像这样的新清单
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.
其次,在你提到的代码中,我添加了对 BuildConfig.DEBUG 的检查:
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);
}
}
这篇关于如何在android上关闭覆盖权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!