mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-14 19:44:53 +00:00
Avoid refrections
This commit is contained in:
parent
1c084fac73
commit
8064b8853f
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user