mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-15 03:54:54 +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();
|
View view = webView.get().getEngine().getView();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> xWalkCls = Class.forName(
|
Class.forName("org.crosswalk.engine.XWalkCordovaView")
|
||||||
"org.crosswalk.engine.XWalkCordovaView");
|
.getMethod("onShow")
|
||||||
|
.invoke(view);
|
||||||
Method onShowMethod =
|
|
||||||
xWalkCls.getMethod("onShow");
|
|
||||||
|
|
||||||
onShowMethod.invoke(view);
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
view.dispatchWindowVisibilityChanged(View.VISIBLE);
|
view.dispatchWindowVisibilityChanged(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -175,4 +171,4 @@ class BackgroundExt {
|
|||||||
return cordova.get().getActivity();
|
return cordova.get().getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
package de.appplant.cordova.plugin.background;
|
package de.appplant.cordova.plugin.background;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -35,7 +36,7 @@ import android.os.PowerManager;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
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
|
* 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);
|
getSystemService(POWER_SERVICE);
|
||||||
|
|
||||||
wakeLock = powerMgr.newWakeLock(
|
wakeLock = powerMgr.newWakeLock(
|
||||||
PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");
|
PARTIAL_WAKE_LOCK, "BackgroundMode");
|
||||||
|
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
}
|
}
|
||||||
@ -183,6 +184,7 @@ public class ForegroundService extends Service {
|
|||||||
context, NOTIFICATION_ID, intent,
|
context, NOTIFICATION_ID, intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
|
||||||
notification.setContentIntent(contentIntent);
|
notification.setContentIntent(contentIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +205,7 @@ public class ForegroundService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Notification notification = makeNotification(settings);
|
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 notification A Notification.Builder instance
|
||||||
* @param settings A JSON dict containing the color definition (red: FF0000)
|
* @param settings A JSON dict containing the color definition (red: FF0000)
|
||||||
*/
|
*/
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
private void setColor(Notification.Builder notification,
|
private void setColor(Notification.Builder notification,
|
||||||
JSONObject settings) {
|
JSONObject settings) {
|
||||||
|
|
||||||
@ -267,10 +268,7 @@ public class ForegroundService extends Service {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int aRGB = Integer.parseInt(hex, 16) + 0xFF000000;
|
int aRGB = Integer.parseInt(hex, 16) + 0xFF000000;
|
||||||
Method setColorMethod = notification.getClass().getMethod(
|
notification.setColor(aRGB);
|
||||||
"setColor", int.class);
|
|
||||||
|
|
||||||
setColorMethod.invoke(notification, aRGB);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -280,8 +278,7 @@ public class ForegroundService extends Service {
|
|||||||
* Shared manager for the notification service.
|
* Shared manager for the notification service.
|
||||||
*/
|
*/
|
||||||
private NotificationManager getNotificationManager() {
|
private NotificationManager getNotificationManager() {
|
||||||
return (NotificationManager) getSystemService(
|
return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
Context.NOTIFICATION_SERVICE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user