use of android.app.NotificationManager in project platform_frameworks_base by android.
the class Tethering method clearTetheredNotification.
private void clearTetheredNotification() {
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null && mLastNotificationId != 0) {
notificationManager.cancelAsUser(null, mLastNotificationId, UserHandle.ALL);
mLastNotificationId = 0;
}
}
use of android.app.NotificationManager in project platform_frameworks_base by android.
the class Vpn method updateAlwaysOnNotificationInternal.
@VisibleForTesting
protected void updateAlwaysOnNotificationInternal(boolean visible) {
final UserHandle user = UserHandle.of(mUserHandle);
final long token = Binder.clearCallingIdentity();
try {
final NotificationManager notificationManager = NotificationManager.from(mContext);
if (!visible) {
notificationManager.cancelAsUser(TAG, 0, user);
return;
}
final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
final PendingIntent configIntent = PendingIntent.getActivityAsUser(mContext, /* request */
0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT, null, user);
final Notification.Builder builder = new Notification.Builder(mContext).setDefaults(0).setSmallIcon(R.drawable.vpn_connected).setContentTitle(mContext.getString(R.string.vpn_lockdown_disconnected)).setContentText(mContext.getString(R.string.vpn_lockdown_config)).setContentIntent(configIntent).setCategory(Notification.CATEGORY_SYSTEM).setPriority(Notification.PRIORITY_LOW).setVisibility(Notification.VISIBILITY_PUBLIC).setOngoing(true).setColor(mContext.getColor(R.color.system_notification_accent_color));
notificationManager.notifyAsUser(TAG, 0, builder.build(), user);
} finally {
Binder.restoreCallingIdentity(token);
}
}
use of android.app.NotificationManager in project platform_frameworks_base by android.
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 void sendNotification() {
final Context context = getContext();
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(StorageManager.ACTION_MANAGE_STORAGE);
lowMemIntent.putExtra("memory", mFreeMem);
lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationManager mNotificationMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence title = context.getText(com.android.internal.R.string.low_internal_storage_view_title);
CharSequence details = context.getText(mIsBootImageOnDisk ? com.android.internal.R.string.low_internal_storage_view_text : com.android.internal.R.string.low_internal_storage_view_text_no_boot);
PendingIntent intent = PendingIntent.getActivityAsUser(context, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
Notification notification = new Notification.Builder(context).setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full).setTicker(title).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setContentTitle(title).setContentText(details).setContentIntent(intent).setStyle(new Notification.BigTextStyle().bigText(details)).setVisibility(Notification.VISIBILITY_PUBLIC).setCategory(Notification.CATEGORY_SYSTEM).build();
notification.flags |= Notification.FLAG_NO_CLEAR;
mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}
use of android.app.NotificationManager in project iosched by google.
the class ShowSessionNotificationDebugAction method run.
@Override
public void run(Context context, Callback callback) {
Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__"));
PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
Intent mapIntent = new Intent(context, MapActivity.class);
mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
mapIntent.putExtra(MapActivity.EXTRA_ROOM, "keynote");
PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
//= PendingIntent.getActivity(context, 0, mapIntent, 0);
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context).setContentTitle("test notification").setContentText("yep, this is a test").setTicker("hey, you got a test").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi).setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
notifBuilder.addAction(R.drawable.ic_stat_map, context.getString(R.string.title_map), piMap);
NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder).setBigContentTitle(context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1));
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(32534, richNotification.build());
}
use of android.app.NotificationManager in project iosched by google.
the class SessionAlarmService method scheduleAlarm.
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID);
final long currentTime = TimeUtils.getCurrentTime(this);
// If the session is already started, do not schedule system notification.
if (currentTime > sessionStart) {
LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
return;
}
// By default, sets alarm to go off at 10 minutes before session start time. If alarm
// offset is provided, alarm is set to go off by that much time from now.
long alarmTime;
if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
alarmTime = sessionStart - MILLI_TEN_MINUTES;
} else {
alarmTime = currentTime + alarmOffset;
}
LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());
final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
// Setting data to ensure intent's uniqueness for different session start times.
notifIntent.setData(new Uri.Builder().authority("com.google.samples.apps.iosched").path(String.valueOf(sessionStart)).build());
notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
LOGD(TAG, "-> Intent extra: session start " + sessionStart);
notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// Schedule an alarm to be fired to notify user of added sessions are about to begin.
LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}
Aggregations