File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
android/src/main/java/com/lesimoes/androidnotificationlistener Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,22 @@ public class RNAndroidNotificationListener extends NotificationListenerService {
15
15
@ Override
16
16
public void onNotificationPosted (StatusBarNotification sbn ) {
17
17
Notification notification = sbn .getNotification ();
18
+
19
+ if (notification == null || notification .extras == null ) return ;
20
+
18
21
String app = sbn .getPackageName ();
19
22
20
- if (notification .extras .getCharSequence (Notification .EXTRA_TITLE ) == null ) return ;
21
- if (notification .extras .getCharSequence (Notification .EXTRA_TEXT ) == null ) return ;
23
+ if (app == null ) app = "Unknown" ;
24
+
25
+ CharSequence titleChars = notification .extras .getCharSequence (Notification .EXTRA_TITLE )
26
+ CharSequence textChars = notification .extras .getCharSequence (Notification .EXTRA_TEXT )
27
+
28
+ if (titleChars == null || textChars == null ) return ;
22
29
23
- String title = notification . extras . getCharSequence ( Notification . EXTRA_TITLE ) .toString ();
24
- String text = notification . extras . getCharSequence ( Notification . EXTRA_TEXT ) .toString ();
30
+ String title = titleChars .toString ();
31
+ String text = textChars .toString ();
25
32
26
- if (text == null ) return ;
33
+ if (text == null || text == "" || title == null || title == "" ) return ;
27
34
28
35
Log .d (TAG , "Notification received: " + app + " | " + title + " | " + text );
29
36
Original file line number Diff line number Diff line change @@ -17,8 +17,7 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
17
17
}
18
18
19
19
@ Override
20
- public List <NativeModule > createNativeModules (
21
- ReactApplicationContext reactContext ) {
20
+ public List <NativeModule > createNativeModules (ReactApplicationContext reactContext ) {
22
21
List <NativeModule > modules = new ArrayList <>();
23
22
24
23
modules .add (new RNAndroidNotificationListenerModule (reactContext ));
You can’t perform that action at this time.
0 commit comments