Parcourir la source

Merge branch 'master' of https://github.com/jbpin/react-native-permissions into jbpin-master

# Conflicts:
#	ReactNativePermissions.js
#	android/build.gradle
Yonah Forst il y a 7 ans
Parent
révision
29b16c2f90

+ 1
- 0
ReactNativePermissions.js Voir le fichier

@@ -26,6 +26,7 @@ const RNPTypes = {
26 26
 		'event',
27 27
 		'photo',
28 28
 		'storage'
29
+		'notification',
29 30
 	]
30 31
 }
31 32
 

+ 15
- 0
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java Voir le fichier

@@ -5,6 +5,7 @@ import android.content.Intent;
5 5
 import android.net.Uri;
6 6
 import android.provider.Settings;
7 7
 import android.support.v4.app.ActivityCompat;
8
+import android.support.v4.app.NotificationManagerCompat;
8 9
 import android.support.v4.content.ContextCompat;
9 10
 import android.support.v4.content.PermissionChecker;
10 11
 
@@ -23,9 +24,11 @@ import java.util.Locale;
23 24
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
24 25
   private final ReactApplicationContext reactContext;
25 26
   private final PermissionsModule mPermissionsModule;
27
+  private final NotificationManagerCompat mNotificationManagerCompat;
26 28
 
27 29
   public enum RNType {
28 30
     LOCATION,
31
+    NOTIFICATION,
29 32
     CAMERA,
30 33
     MICROPHONE,
31 34
     CONTACTS,
@@ -38,6 +41,7 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
38 41
     super(reactContext);
39 42
     this.reactContext = reactContext;
40 43
     mPermissionsModule = new PermissionsModule(this.reactContext);
44
+    mNotificationManagerCompat = NotificationManagerCompat.from(this.reactContext);
41 45
   }
42 46
 
43 47
   @Override
@@ -55,6 +59,15 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
55 59
       return;
56 60
     }
57 61
 
62
+    if(permission.equals("notification")) {
63
+      if (mNotificationManagerCompat.areNotificationsEnabled()) {
64
+        promise.resolve("authorized");
65
+      } else {
66
+        promise.resolve("denied");
67
+      }
68
+      return;
69
+    }
70
+
58 71
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
59 72
     switch (result) {
60 73
       case PermissionChecker.PERMISSION_DENIED:
@@ -131,6 +144,8 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
131 144
       case STORAGE:
132 145
       case PHOTO:
133 146
         return Manifest.permission.READ_EXTERNAL_STORAGE;
147
+      case NOTIFICATION:
148
+        return permission;
134 149
       default:
135 150
         return null;
136 151
     }