mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-15 03:54:54 +00:00
Re-add color
This commit is contained in:
parent
aed89d8503
commit
f7e5684a66
@ -29,11 +29,15 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* something the user is actively aware of and thus not a candidate for killing
|
* something the user is actively aware of and thus not a candidate for killing
|
||||||
@ -158,6 +162,8 @@ public class ForegroundService extends Service {
|
|||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setSmallIcon(getIconResId());
|
.setSmallIcon(getIconResId());
|
||||||
|
|
||||||
|
setColor(notification, settings);
|
||||||
|
|
||||||
if (intent != null && settings.optBoolean("resume")) {
|
if (intent != null && settings.optBoolean("resume")) {
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
PendingIntent contentIntent = PendingIntent.getActivity(
|
||||||
context, NOTIFICATION_ID, intent,
|
context, NOTIFICATION_ID, intent,
|
||||||
@ -211,4 +217,36 @@ public class ForegroundService extends Service {
|
|||||||
|
|
||||||
return resId;
|
return resId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set notification color if its supported by the SDK.
|
||||||
|
*
|
||||||
|
* @param notification
|
||||||
|
* A Notification.Builder instance
|
||||||
|
* @param settings
|
||||||
|
* A JSON dict containing the color definition (red: FF0000)
|
||||||
|
*/
|
||||||
|
private void setColor(Notification.Builder notification,
|
||||||
|
JSONObject settings) {
|
||||||
|
|
||||||
|
String hex = settings.optString("color", null);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT < 21 || hex == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int aRGB = Integer.parseInt(hex, 16) + 0xFF000000;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Method setColorMethod = notification.getClass().getMethod(
|
||||||
|
"setColor", int.class);
|
||||||
|
|
||||||
|
setColorMethod.invoke(notification, aRGB);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ exports._defaults = {
|
|||||||
ticker: 'Running in background',
|
ticker: 'Running in background',
|
||||||
resume: true,
|
resume: true,
|
||||||
silent: false,
|
silent: false,
|
||||||
|
color: undefined,
|
||||||
icon: 'icon'
|
icon: 'icon'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user