use of android.app.Notification in project XPrivacy by M66B.
the class UpdateService method notifyProgress.
private static void notifyProgress(Context context, int id, String format, int percentage) {
String message = String.format(format, String.format("%d %%", percentage));
Util.log(null, Log.WARN, message);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setContentText(message);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(percentage == 100);
builder.setOngoing(percentage < 100);
Notification notification = builder.build();
notificationManager.notify(id, notification);
}
use of android.app.Notification in project XPrivacy by M66B.
the class UpdateService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Check if work
if (intent == null) {
stopSelf();
return 0;
}
// Flush
if (cFlush.equals(intent.getAction())) {
try {
PrivacyService.getClient().flush();
XApplication.manage(this, 0, XApplication.cActionFlush);
} catch (Throwable ex) {
Util.bug(null, ex);
}
stopSelf();
return 0;
}
// Update
if (cUpdate.equals(intent.getAction())) {
if (Util.hasProLicense(this) != null) {
int userId = Util.getUserId(Process.myUid());
boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false);
if (updates)
new ActivityShare.UpdateTask(this).execute();
}
stopSelf();
return 0;
}
// Check action
Bundle extras = intent.getExtras();
if (extras.containsKey(cAction)) {
final int action = extras.getInt(cAction);
Util.log(null, Log.WARN, "Service received action=" + action + " flags=" + flags);
// Check service
if (PrivacyService.getClient() == null) {
Util.log(null, Log.ERROR, "Service not available");
stopSelf();
return 0;
}
// Start foreground service
NotificationCompat.Builder builder = new NotificationCompat.Builder(UpdateService.this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle(getString(R.string.app_name));
builder.setContentText(getString(R.string.msg_service));
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(false);
builder.setOngoing(true);
Notification notification = builder.build();
startForeground(Util.NOTIFY_SERVICE, notification);
// Start worker
mWorkerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Check action
if (action == cActionBoot) {
// Boot received
migrate(UpdateService.this);
upgrade(UpdateService.this);
randomize(UpdateService.this);
} else if (action == cActionUpdated) {
// Self updated
upgrade(UpdateService.this);
} else
Util.log(null, Log.ERROR, "Unknown action=" + action);
// Done
stopForeground(true);
stopSelf();
} catch (Throwable ex) {
Util.bug(null, ex);
// Leave service running
}
}
});
mWorkerThread.start();
} else
Util.log(null, Log.ERROR, "Action missing");
return START_STICKY;
}
use of android.app.Notification in project XPrivacy by M66B.
the class PrivacyService method notifyException.
private void notifyException(Throwable ex) {
Util.bug(null, ex);
if (mNotified)
return;
Context context = getContext();
if (context == null)
return;
try {
Intent intent = new Intent("biz.bokhorst.xprivacy.action.EXCEPTION");
intent.putExtra("Message", ex.toString());
context.sendBroadcast(intent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Build notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.app_name));
notificationBuilder.setContentText(ex.toString());
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setAutoCancel(true);
Notification notification = notificationBuilder.build();
// Display notification
notificationManager.notify(Util.NOTIFY_CORRUPT, notification);
mNotified = true;
} catch (Throwable exex) {
Util.bug(null, exex);
}
}
use of android.app.Notification in project XPrivacy by M66B.
the class BootReceiver method onReceive.
@Override
public void onReceive(final Context context, Intent bootIntent) {
// Start boot update
Intent changeIntent = new Intent();
changeIntent.setClass(context, UpdateService.class);
changeIntent.putExtra(UpdateService.cAction, UpdateService.cActionBoot);
context.startService(changeIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Check if Xposed enabled
if (Util.isXposedEnabled() && PrivacyService.checkClient())
try {
if (PrivacyService.getClient().databaseCorrupt()) {
// Build notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.app_name));
notificationBuilder.setContentText(context.getString(R.string.msg_corrupt));
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setAutoCancel(true);
Notification notification = notificationBuilder.build();
// Display notification
notificationManager.notify(Util.NOTIFY_CORRUPT, notification);
} else
context.sendBroadcast(new Intent("biz.bokhorst.xprivacy.action.ACTIVE"));
} catch (Throwable ex) {
Util.bug(null, ex);
}
else {
// Create Xposed installer intent
// @formatter:off
Intent xInstallerIntent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION").setPackage("de.robv.android.xposed.installer").putExtra("section", "modules").putExtra("module", context.getPackageName()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// @formatter:on
PendingIntent pi = (xInstallerIntent == null ? null : PendingIntent.getActivity(context, 0, xInstallerIntent, PendingIntent.FLAG_UPDATE_CURRENT));
// Build notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.app_name));
notificationBuilder.setContentText(context.getString(R.string.app_notenabled));
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setAutoCancel(true);
if (pi != null)
notificationBuilder.setContentIntent(pi);
Notification notification = notificationBuilder.build();
// Display notification
notificationManager.notify(Util.NOTIFY_NOTXPOSED, notification);
}
}
use of android.app.Notification in project FileExplorer by MiCode.
the class FTPServerService method setupNotification.
private void setupNotification() {
// http://developer.android.com/guide/topics/ui/notifiers/notifications.html
// Instantiate a Notification
int icon = R.drawable.notification;
CharSequence tickerText = getString(R.string.notif_server_starting);
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// Define Notification's message and Intent
CharSequence contentTitle = getString(R.string.notif_title);
CharSequence contentText = "";
InetAddress address = FTPServerService.getWifiIp();
if (address != null) {
String port = ":" + FTPServerService.getPort();
contentText = "ftp://" + address.getHostAddress() + (FTPServerService.getPort() == 21 ? "" : port);
}
Intent notificationIntent = new Intent(this, FileExplorerTabActivity.class);
notificationIntent.putExtra(GlobalConsts.INTENT_EXTRA_TAB, 2);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(123453, notification);
myLog.d("Notication setup done");
}
Aggregations