Browse Source

added notification permission for android

Jean-Baptiste Pin 8 years ago
parent
commit
ca7b15cad1

+ 13
- 1
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java View File

5
 import android.net.Uri;
5
 import android.net.Uri;
6
 import android.provider.Settings;
6
 import android.provider.Settings;
7
 import android.support.v4.app.ActivityCompat;
7
 import android.support.v4.app.ActivityCompat;
8
+import android.support.v4.app.NotificationManagerCompat;
8
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.PermissionChecker;
10
 import android.support.v4.content.PermissionChecker;
10
 
11
 
24
 
25
 
25
   public enum RNType {
26
   public enum RNType {
26
     LOCATION,
27
     LOCATION,
28
+    NOTIFICATION,
27
     CAMERA,
29
     CAMERA,
28
     MICROPHONE,
30
     MICROPHONE,
29
     CONTACTS,
31
     CONTACTS,
35
     super(reactContext);
37
     super(reactContext);
36
     this.reactContext = reactContext;
38
     this.reactContext = reactContext;
37
     mPermissionsModule = new PermissionsModule(this.reactContext);
39
     mPermissionsModule = new PermissionsModule(this.reactContext);
40
+    this.notificationManagerCompat = NotificationManagerCompat.from(reactContext);
38
   }
41
   }
39
 
42
 
40
   @Override
43
   @Override
52
       return;
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
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
67
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
56
     switch (result) {
68
     switch (result) {
57
       case PermissionChecker.PERMISSION_DENIED:
69
       case PermissionChecker.PERMISSION_DENIED:
121
       case PHOTOS:
133
       case PHOTOS:
122
         return Manifest.permission.READ_EXTERNAL_STORAGE;
134
         return Manifest.permission.READ_EXTERNAL_STORAGE;
123
       default:
135
       default:
124
-        return null;
136
+        return permission;
125
     }
137
     }
126
   }
138
   }
127
 
139