Skip to content

Commit cfa89ba

Browse files
committed
Fix error ocurring while calling .toString() to a null object
1 parent 8214b10 commit cfa89ba

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListener.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ public class RNAndroidNotificationListener extends NotificationListenerService {
1616
public void onNotificationPosted(StatusBarNotification sbn) {
1717
Notification notification = sbn.getNotification();
1818
String app = sbn.getPackageName();
19+
20+
if (notification.extras.getCharSequence(Notification.EXTRA_TITLE) == null) return;
21+
if (notification.extras.getCharSequence(Notification.EXTRA_TEXT) == null) return;
22+
1923
String title = notification.extras.getCharSequence(Notification.EXTRA_TITLE).toString();
2024
String text = notification.extras.getCharSequence(Notification.EXTRA_TEXT).toString();
2125

22-
Log.d(TAG, "Notification received: "+app+" | "+title+" | "+text);
26+
if (text == null) return;
2327

24-
if (text == null) {
25-
return;
26-
}
28+
Log.d(TAG, "Notification received: " + app + " | " + title + " | " + text);
2729

2830
WritableMap params = Arguments.createMap();
2931
params.putString("app", app);

android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListenerModule.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919

2020
public class RNAndroidNotificationListenerModule extends ReactContextBaseJavaModule {
2121
private static ReactApplicationContext reactContext;
22+
private static final String TAG = "RNAndroidNotificationListener";
2223

2324
public RNAndroidNotificationListenerModule(ReactApplicationContext context) {
2425
super(context);
26+
2527
reactContext = context;
2628
}
2729

30+
@Override
2831
public String getName() {
29-
return "RNAndroidNotificationListener";
32+
return TAG;
3033
}
3134

3235
@ReactMethod
@@ -54,10 +57,6 @@ public void requestPermission() {
5457
reactContext.startActivity(i);
5558
}
5659

57-
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {}
58-
59-
public void onNewIntent(Intent intent){}
60-
6160
public static void sendEvent(String event, WritableMap params) {
6261
if (reactContext == null) return;
6362

0 commit comments

Comments
 (0)