rn-android-overlay-permission

1.0.5 • Public • Published

0x1bitcrack3r

rn-android-overlay-permission

This module is to request screen overlay permission from user in react-native based android application

Getting started

$ npm install rn-android-overlay-permission --save

Mostly automatic installation

$ react-native link rn-android-overlay-permission

Add these permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.overlaypermission.OverlayPermissionPackage; to the imports at the top of the file
  1. Append the following lines to android/settings.gradle:

        include ':rn-android-overlay-permission'
        project(':rn-android-overlay-permission').projectDir = new File(rootProject.projectDir, '../node_modules/rn-android-overlay-permission/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

        compile project(':rn-android-overlay-permission')
    

Usage

//requestOverlayPermission Navigates to permission settings
OverlayPermissionModule.requestOverlayPermission();
import OverlayPermissionModule from "rn-android-overlay-permission";
 
if (Platform.OS === "android") {
  OverlayPermissionModule.isRequestOverlayPermissionGranted((status: any) => {
    if (status) {
      Alert.alert(
        "Permissions",
        "Overlay Permission",
        [
          {
            text: "Cancel",
            onPress: () => console.log("Cancel Pressed"),
            style: "cancel",
          },
          {
            text: "OK",
            onPress: () => OverlayPermissionModule.requestOverlayPermission(),
          },
        ],
        { cancelable: false }
      );
    }
  });
}

Package Sidebar

Install

npm i rn-android-overlay-permission

Weekly Downloads

188

Version

1.0.5

License

ISC

Unpacked Size

7.46 kB

Total Files

8

Last publish

Collaborators

  • 0x1bitcrack3r