mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-08 15:35:24 +02:00
Handle case where notification.extras is not available #174
This commit is contained in:
parent
394a0905dc
commit
4616dcc965
@ -156,6 +156,9 @@ public class GBApplication extends Application {
|
|||||||
dbLock.unlock();
|
dbLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isRunningOnKitkatOrLater() {
|
||||||
|
return VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||||
|
}
|
||||||
public static boolean isRunningLollipopOrLater() {
|
public static boolean isRunningLollipopOrLater() {
|
||||||
return VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
return VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
}
|
}
|
||||||
@ -190,5 +193,4 @@ public class GBApplication extends Application {
|
|||||||
blacklist.remove(packageName);
|
blacklist.remove(packageName);
|
||||||
saveBlackList();
|
saveBlackList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -11,6 +12,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -216,17 +218,26 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
|
|
||||||
LOG.info("Processing notification from source " + source);
|
LOG.info("Processing notification from source " + source);
|
||||||
|
|
||||||
|
if (GBApplication.isRunningOnKitkatOrLater()) {
|
||||||
|
dissectNotificationTo(notification, notificationSpec);
|
||||||
|
}
|
||||||
|
notificationSpec.id = (int) sbn.getPostTime(); //FIMXE: a truly unique id would be better
|
||||||
|
GBApplication.deviceService().onNotification(notificationSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||||
|
private void dissectNotificationTo(Notification notification, NotificationSpec notificationSpec) {
|
||||||
Bundle extras = notification.extras;
|
Bundle extras = notification.extras;
|
||||||
notificationSpec.title = extras.getCharSequence(Notification.EXTRA_TITLE).toString();
|
CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE);
|
||||||
|
if (title != null) {
|
||||||
|
notificationSpec.title = title.toString();
|
||||||
|
}
|
||||||
if (extras.containsKey(Notification.EXTRA_TEXT)) {
|
if (extras.containsKey(Notification.EXTRA_TEXT)) {
|
||||||
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
|
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
|
||||||
if (contentCS != null) {
|
if (contentCS != null) {
|
||||||
notificationSpec.body = contentCS.toString();
|
notificationSpec.body = contentCS.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationSpec.id = (int) sbn.getPostTime(); //FIMXE: a truly unique id would be better
|
|
||||||
GBApplication.deviceService().onNotification(notificationSpec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isServiceRunning() {
|
private boolean isServiceRunning() {
|
||||||
|
Loading…
Reference in New Issue
Block a user