Search in sources :

Example 16 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class DeviceStorageMonitorService method sendNotification.

/**
    * This method sends a notification to NotificationManager to display
    * an error dialog indicating low disk space and launch the Installer
    * application
    */
private final void sendNotification() {
    if (localLOGV)
        Slog.i(TAG, "Sending low memory notification");
    //log the event to event log with the amount of free storage(in bytes) left on the device
    EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
    //  Pack up the values and broadcast them to everyone
    Intent lowMemIntent = new Intent(Environment.isExternalStorageEmulated() ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
    lowMemIntent.putExtra("memory", mFreeMem);
    lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationManager mNotificationMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence title = mContext.getText(com.android.internal.R.string.low_internal_storage_view_title);
    CharSequence details = mContext.getText(com.android.internal.R.string.low_internal_storage_view_text);
    PendingIntent intent = PendingIntent.getActivityAsUser(mContext, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
    Notification notification = new Notification();
    notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
    notification.tickerText = title;
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.setLatestEventInfo(getUiContext(), title, details, intent);
    mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
    mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 17 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class DeviceStorageMonitorService method cancelNotification.

/**
     * Cancels low storage notification and sends OK intent.
     */
private final void cancelNotification() {
    if (localLOGV)
        Slog.i(TAG, "Canceling low memory notification");
    NotificationManager mNotificationMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    //cancel notification since memory has been freed
    mNotificationMgr.cancelAsUser(null, LOW_MEMORY_NOTIFICATION_ID, UserHandle.ALL);
    mContext.removeStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
    mContext.sendBroadcastAsUser(mStorageOkIntent, UserHandle.ALL);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 18 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class Tethering method showTetheredNotification.

private void showTetheredNotification(int icon) {
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        return;
    }
    if (mTetheredNotification != null) {
        if (mTetheredNotification.icon == icon) {
            return;
        }
        notificationManager.cancelAsUser(null, mTetheredNotification.icon, UserHandle.ALL);
    }
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
    Resources r = Resources.getSystem();
    CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
    CharSequence message = r.getText(com.android.internal.R.string.tethered_notification_message);
    if (mTetheredNotification == null) {
        mTetheredNotification = new Notification();
        mTetheredNotification.when = 0;
    }
    mTetheredNotification.icon = icon;
    mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
    mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
    mTetheredNotification.tickerText = title;
    mTetheredNotification.setLatestEventInfo(getUiContext(), title, message, pi);
    notificationManager.notifyAsUser(null, mTetheredNotification.icon, mTetheredNotification, UserHandle.ALL);
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 19 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class Tethering method clearTetheredNotification.

private void clearTetheredNotification() {
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager != null && mTetheredNotification != null) {
        notificationManager.cancelAsUser(null, mTetheredNotification.icon, UserHandle.ALL);
        mTetheredNotification = null;
    }
}
Also used : NotificationManager(android.app.NotificationManager)

Example 20 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class Vpn method showNotification.

private void showNotification(VpnConfig config, String label, Bitmap icon) {
    if (!mEnableNotif)
        return;
    mStatusIntent = VpnConfig.getIntentForStatusPanel(mContext, config);
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm != null) {
        String title = (label == null) ? mContext.getString(R.string.vpn_title) : mContext.getString(R.string.vpn_title_long, label);
        String text = (config.session == null) ? mContext.getString(R.string.vpn_text) : mContext.getString(R.string.vpn_text_long, config.session);
        config.startTime = SystemClock.elapsedRealtime();
        Notification notification = new Notification.Builder(mContext).setSmallIcon(R.drawable.vpn_connected).setLargeIcon(icon).setContentTitle(title).setContentText(text).setContentIntent(mStatusIntent).setDefaults(0).setOngoing(true).build();
        nm.notifyAsUser(null, R.drawable.vpn_connected, notification, UserHandle.ALL);
    }
}
Also used : NotificationManager(android.app.NotificationManager) Notification(android.app.Notification)

Aggregations

NotificationManager (android.app.NotificationManager)374 Intent (android.content.Intent)187 PendingIntent (android.app.PendingIntent)184 Notification (android.app.Notification)147 NotificationCompat (android.support.v4.app.NotificationCompat)107 Context (android.content.Context)32 Bitmap (android.graphics.Bitmap)24 Uri (android.net.Uri)23 Resources (android.content.res.Resources)22 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)20 TaskStackBuilder (android.app.TaskStackBuilder)15 Bundle (android.os.Bundle)15 StatusBarNotification (android.service.notification.StatusBarNotification)15 Random (java.util.Random)14 BitmapFactory (android.graphics.BitmapFactory)13 SharedPreferences (android.content.SharedPreferences)12 ComponentName (android.content.ComponentName)10 IntentFilter (android.content.IntentFilter)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9