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);
}
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);
}
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);
}
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;
}
}
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);
}
}
Aggregations