mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-13 10:31:03 +01:00
64 lines
2.3 KiB
Java
64 lines
2.3 KiB
Java
|
package nodomain.freeyourgadget.gadgetbridge;
|
||
|
|
||
|
import android.app.Notification;
|
||
|
import android.app.NotificationManager;
|
||
|
import android.app.PendingIntent;
|
||
|
import android.content.ComponentName;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.content.pm.PackageManager;
|
||
|
import android.support.v4.app.NotificationCompat;
|
||
|
|
||
|
public class GB {
|
||
|
public static final int NOTIFICATION_ID = 1;
|
||
|
|
||
|
public static Notification createNotification(String text, Context context) {
|
||
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
||
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
||
|
notificationIntent, 0);
|
||
|
|
||
|
return new NotificationCompat.Builder(context)
|
||
|
.setContentTitle("Gadgetbridge")
|
||
|
.setTicker(text)
|
||
|
.setContentText(text)
|
||
|
.setSmallIcon(R.drawable.ic_notification)
|
||
|
.setContentIntent(pendingIntent)
|
||
|
.setOngoing(true).build();
|
||
|
}
|
||
|
|
||
|
public static void updateNotification(String text, Context context) {
|
||
|
Notification notification = createNotification(text, context);
|
||
|
|
||
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||
|
nm.notify(NOTIFICATION_ID, notification);
|
||
|
}
|
||
|
|
||
|
public static void setReceiversEnableState(boolean enable, Context context) {
|
||
|
final Class[] receiverClasses = {
|
||
|
PhoneCallReceiver.class,
|
||
|
SMSReceiver.class,
|
||
|
K9Receiver.class,
|
||
|
MusicPlaybackReceiver.class,
|
||
|
//NotificationListener.class, // disabling this leads to loss of permission to read notifications
|
||
|
};
|
||
|
|
||
|
int newState;
|
||
|
|
||
|
if (enable) {
|
||
|
newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||
|
} else {
|
||
|
newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||
|
}
|
||
|
|
||
|
PackageManager pm = context.getPackageManager();
|
||
|
|
||
|
for (Class receiverClass : receiverClasses) {
|
||
|
ComponentName compName = new ComponentName(context, receiverClass);
|
||
|
|
||
|
pm.setComponentEnabledSetting(compName, newState, PackageManager.DONT_KILL_APP);
|
||
|
}
|
||
|
}
|
||
|
}
|