Browse Source

added android notification support

Jean-Baptiste Pin 8 years ago
parent
commit
584a76e9d7

+ 4
- 3
ReactNativePermissions.js View File

15
 		'reminder',
15
 		'reminder',
16
 		'bluetooth',
16
 		'bluetooth',
17
 		'notification',
17
 		'notification',
18
-		'backgroundRefresh', 
18
+		'backgroundRefresh',
19
 	],
19
 	],
20
 	android: [
20
 	android: [
21
 		'location',
21
 		'location',
24
 		'contacts',
24
 		'contacts',
25
 		'event',
25
 		'event',
26
 		'photos',
26
 		'photos',
27
+		'notification',
27
 	]
28
 	]
28
 }
29
 }
29
 
30
 
66
 	}
67
 	}
67
 
68
 
68
 	requestPermission(permission, type) {
69
 	requestPermission(permission, type) {
69
-		let options; 
70
+		let options;
70
 
71
 
71
 		if (!this.getPermissionTypes().includes(permission)) {
72
 		if (!this.getPermissionTypes().includes(permission)) {
72
 			return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on ${Platform.OS}`)
73
 			return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on ${Platform.OS}`)
89
 		function processNext() {
90
 		function processNext() {
90
 			i--
91
 			i--
91
 			let p = permissions[i]
92
 			let p = permissions[i]
92
-			
93
+
93
 			if (!p) {
94
 			if (!p) {
94
 				return Promise.resolve(obj)
95
 				return Promise.resolve(obj)
95
 			}
96
 			}

+ 5
- 4
android/build.gradle View File

1
 buildscript {
1
 buildscript {
2
     repositories {
2
     repositories {
3
-        jcenter()
3
+        mavenCentral()
4
     }
4
     }
5
 
5
 
6
     dependencies {
6
     dependencies {
11
 apply plugin: 'com.android.library'
11
 apply plugin: 'com.android.library'
12
 
12
 
13
 android {
13
 android {
14
-    compileSdkVersion 23
15
-    buildToolsVersion "23.0.1"
14
+    compileSdkVersion 24
15
+    buildToolsVersion "24.0.1"
16
 
16
 
17
     defaultConfig {
17
     defaultConfig {
18
         minSdkVersion 18
18
         minSdkVersion 18
19
-        targetSdkVersion 23
19
+        targetSdkVersion 24
20
         versionCode 1
20
         versionCode 1
21
         versionName "1.0"
21
         versionName "1.0"
22
     }
22
     }
31
 
31
 
32
 dependencies {
32
 dependencies {
33
     compile 'com.facebook.react:react-native:+'
33
     compile 'com.facebook.react:react-native:+'
34
+    compile 'com.android.support:support-v4:24.1.1'
34
 }
35
 }

+ 4
- 3
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java View File

22
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
22
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
23
   private final ReactApplicationContext reactContext;
23
   private final ReactApplicationContext reactContext;
24
   private final PermissionsModule mPermissionsModule;
24
   private final PermissionsModule mPermissionsModule;
25
+  private final NotificationManagerCompat mNotificationManagerCompat;
25
 
26
 
26
   public enum RNType {
27
   public enum RNType {
27
     LOCATION,
28
     LOCATION,
37
     super(reactContext);
38
     super(reactContext);
38
     this.reactContext = reactContext;
39
     this.reactContext = reactContext;
39
     mPermissionsModule = new PermissionsModule(this.reactContext);
40
     mPermissionsModule = new PermissionsModule(this.reactContext);
40
-    this.notificationManagerCompat = NotificationManagerCompat.from(reactContext);
41
+    mNotificationManagerCompat = NotificationManagerCompat.from(this.reactContext);
41
   }
42
   }
42
 
43
 
43
   @Override
44
   @Override
55
       return;
56
       return;
56
     }
57
     }
57
 
58
 
58
-    if(permission == 'notification') {
59
-      if (this.notificationManagerCompat.areNotificationsEnabled()) {
59
+    if(permission.equals('notification')) {
60
+      if (mNotificationManagerCompat.areNotificationsEnabled()) {
60
         promise.resolve("authorized");
61
         promise.resolve("authorized");
61
       } else {
62
       } else {
62
         promise.resolve("denied");
63
         promise.resolve("denied");