瀏覽代碼

added notification permission for android

Jean-Baptiste Pin 8 年之前
父節點
當前提交
ca7b15cad1

+ 13
- 1
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java 查看文件

@@ -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
 
@@ -24,6 +25,7 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
24 25
 
25 26
   public enum RNType {
26 27
     LOCATION,
28
+    NOTIFICATION,
27 29
     CAMERA,
28 30
     MICROPHONE,
29 31
     CONTACTS,
@@ -35,6 +37,7 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
35 37
     super(reactContext);
36 38
     this.reactContext = reactContext;
37 39
     mPermissionsModule = new PermissionsModule(this.reactContext);
40
+    this.notificationManagerCompat = NotificationManagerCompat.from(reactContext);
38 41
   }
39 42
 
40 43
   @Override
@@ -52,6 +55,15 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
52 55
       return;
53 56
     }
54 57
 
58
+    if(permission == 'notification') {
59
+      if (this.notificationManagerCompat.areNotificationsEnabled()) {
60
+        promise.resolve("authorized");
61
+      } else {
62
+        promise.resolve("denied");
63
+      }
64
+      return;
65
+    }
66
+
55 67
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
56 68
     switch (result) {
57 69
       case PermissionChecker.PERMISSION_DENIED:
@@ -121,7 +133,7 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
121 133
       case PHOTOS:
122 134
         return Manifest.permission.READ_EXTERNAL_STORAGE;
123 135
       default:
124
-        return null;
136
+        return permission;
125 137
     }
126 138
   }
127 139