Search in sources :

Example 26 with Notification

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);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 27 with 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;
}
Also used : Bundle(android.os.Bundle) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 28 with Notification

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);
    }
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) Notification(android.app.Notification)

Example 29 with Notification

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);
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 30 with 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");
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) InetAddress(java.net.InetAddress) Notification(android.app.Notification)

Aggregations

Notification (android.app.Notification)552 PendingIntent (android.app.PendingIntent)265 Intent (android.content.Intent)240 NotificationManager (android.app.NotificationManager)122 StatusBarNotification (android.service.notification.StatusBarNotification)96 NotificationCompat (android.support.v4.app.NotificationCompat)58 Resources (android.content.res.Resources)55 Context (android.content.Context)47 Bitmap (android.graphics.Bitmap)47 Test (org.junit.Test)45 ITransientNotification (android.app.ITransientNotification)32 RemoteViews (android.widget.RemoteViews)30 RemoteException (android.os.RemoteException)24 UserHandle (android.os.UserHandle)17 Date (java.util.Date)16 Uri (android.net.Uri)15 Bundle (android.os.Bundle)13 File (java.io.File)13 ApplicationInfo (android.content.pm.ApplicationInfo)12 SuppressLint (android.annotation.SuppressLint)11