diff --git a/src/android/BackgroundExt.java b/src/android/BackgroundExt.java index 69e4ec6..00043a0 100644 --- a/src/android/BackgroundExt.java +++ b/src/android/BackgroundExt.java @@ -126,13 +126,9 @@ class BackgroundExt { View view = webView.get().getEngine().getView(); try { - Class xWalkCls = Class.forName( - "org.crosswalk.engine.XWalkCordovaView"); - - Method onShowMethod = - xWalkCls.getMethod("onShow"); - - onShowMethod.invoke(view); + Class.forName("org.crosswalk.engine.XWalkCordovaView") + .getMethod("onShow") + .invoke(view); } catch (Exception e){ view.dispatchWindowVisibilityChanged(View.VISIBLE); } @@ -175,4 +171,4 @@ class BackgroundExt { return cordova.get().getActivity(); } -} \ No newline at end of file +} diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index 76cf918..2a7d24f 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -21,6 +21,7 @@ package de.appplant.cordova.plugin.background; +import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -35,7 +36,7 @@ import android.os.PowerManager; import org.json.JSONObject; -import java.lang.reflect.Method; +import static android.os.PowerManager.PARTIAL_WAKE_LOCK; /** * Puts the service in a foreground state, where the system considers it to be @@ -119,7 +120,7 @@ public class ForegroundService extends Service { getSystemService(POWER_SERVICE); wakeLock = powerMgr.newWakeLock( - PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode"); + PARTIAL_WAKE_LOCK, "BackgroundMode"); wakeLock.acquire(); } @@ -183,6 +184,7 @@ public class ForegroundService extends Service { context, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); + notification.setContentIntent(contentIntent); } @@ -203,9 +205,7 @@ public class ForegroundService extends Service { } Notification notification = makeNotification(settings); - - getNotificationManager().notify( - NOTIFICATION_ID, notification); + getNotificationManager().notify(NOTIFICATION_ID, notification); } /** @@ -257,6 +257,7 @@ public class ForegroundService extends Service { * @param notification A Notification.Builder instance * @param settings A JSON dict containing the color definition (red: FF0000) */ + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void setColor(Notification.Builder notification, JSONObject settings) { @@ -267,10 +268,7 @@ public class ForegroundService extends Service { try { int aRGB = Integer.parseInt(hex, 16) + 0xFF000000; - Method setColorMethod = notification.getClass().getMethod( - "setColor", int.class); - - setColorMethod.invoke(notification, aRGB); + notification.setColor(aRGB); } catch (Exception e) { e.printStackTrace(); } @@ -280,8 +278,7 @@ public class ForegroundService extends Service { * Shared manager for the notification service. */ private NotificationManager getNotificationManager() { - return (NotificationManager) getSystemService( - Context.NOTIFICATION_SERVICE); + return (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } }