React Native

Fix "permission denied for this window type" when adding React Native to an Android app

Overview of React-Native Integration with Existing Android Apps

If you have followed the react-native Integration With Existing Apps tutorial with a target SDK version > 23, you may get the "permission denied for this window type" error when you open the react-native view. The problem is the new android permission system.

Solution

To get rid of this error, you must request the new permissions from the user.

In the previous Activity, you may have something like this to go to your react Activity.

++pre>@Override
public void onClick(View v) {
   Intent intent = new Intent(this, ReactDemoActivity.class);
   startActivity(intent);
}++/pre>

Instead of going directly on your new Page, you must request for permission first:

++pre>    private static final int OVERLAY_PERMISSION_CODE =5463 ; // can be anything

   @Override
   public void onClick(View v) {

       if (Build.VERSION.SDK_INT >= 23) {
           if (!Settings.canDrawOverlays(this)) {

               // Open the permission page
               Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                       Uri.parse("package:" + getPackageName()));
               startActivityForResult(intent, OVERLAY_PERMISSION_CODE);
               return;
           }
       }

       // if not needed, go directly on the new Activity
       goToReactActivity();
   }

   @Override
   protected void onActivityResult(int requestCode, int resultCode,  Intent data) {

       // If the permission has been checked
       if (requestCode == OVERLAY_PERMISSION_CODE) {
           if (Settings.canDrawOverlays(this)) {
               goToReactActivity();
           }
       }
   }

   private void goToReactActivity() {
       Intent intent = new Intent(this, ReactDemoActivity.class);
       startActivity(intent);
   }++/pre>

To have a complete example of a react-native integration in an Android existing application, you can see this commit.

Other common issues

If your application still crashes on the react-native Activity on release, you may have forgotten to Bundle your javascript.

Last but not least, you may also have some problems with 32-bit architecture, like this:

++pre>++code>java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.bamlab.reactIntegration/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit
++/code>++/pre>

In that case, add this to your ++code>build.gradle++/code> :

++pre>++code>android {
   defaultConfig {
       ndk {
           abiFilters "armeabi-v7a", "x86"
       }
   }
}
++/code>++/pre>

You will also need to edit your ++code>gradle.properties++/code>

++pre>++code>android.useDeprecatedNdk=true
++/code>++/pre>

Développeur mobile ?

Rejoins nos équipes