use of android.app.NotificationManager in project android_frameworks_base by AOSPA.
the class Tethering method showTetheredNotification.
private void showTetheredNotification(int icon) {
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (mLastNotificationId != 0) {
if (mLastNotificationId == icon) {
return;
}
notificationManager.cancelAsUser(null, mLastNotificationId, UserHandle.ALL);
mLastNotificationId = 0;
}
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 (mTetheredNotificationBuilder == null) {
mTetheredNotificationBuilder = new Notification.Builder(mContext);
mTetheredNotificationBuilder.setWhen(0).setOngoing(true).setColor(mContext.getColor(com.android.internal.R.color.system_notification_accent_color)).setVisibility(Notification.VISIBILITY_PUBLIC).setCategory(Notification.CATEGORY_STATUS);
}
mTetheredNotificationBuilder.setSmallIcon(icon).setContentTitle(title).setContentText(message).setContentIntent(pi);
mLastNotificationId = icon;
notificationManager.notifyAsUser(null, mLastNotificationId, mTetheredNotificationBuilder.build(), UserHandle.ALL);
}
use of android.app.NotificationManager in project Sunshine-Version-2 by udacity.
the class SunshineSyncAdapter method notifyWeather.
private void notifyWeather() {
Context context = getContext();
//checking the last update and notify if it' the first of the day
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key);
boolean displayNotifications = prefs.getBoolean(displayNotificationsKey, Boolean.parseBoolean(context.getString(R.string.pref_enable_notifications_default)));
if (displayNotifications) {
String lastNotificationKey = context.getString(R.string.pref_last_notification);
long lastSync = prefs.getLong(lastNotificationKey, 0);
if (System.currentTimeMillis() - lastSync >= DAY_IN_MILLIS) {
// Last sync was more than 1 day ago, let's send a notification with the weather.
String locationQuery = Utility.getPreferredLocation(context);
Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis());
// we'll query our contentProvider, as always
Cursor cursor = context.getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);
if (cursor.moveToFirst()) {
int weatherId = cursor.getInt(INDEX_WEATHER_ID);
double high = cursor.getDouble(INDEX_MAX_TEMP);
double low = cursor.getDouble(INDEX_MIN_TEMP);
String desc = cursor.getString(INDEX_SHORT_DESC);
int iconId = Utility.getIconResourceForWeatherCondition(weatherId);
Resources resources = context.getResources();
Bitmap largeIcon = BitmapFactory.decodeResource(resources, Utility.getArtResourceForWeatherCondition(weatherId));
String title = context.getString(R.string.app_name);
// Define the text of the forecast.
String contentText = String.format(context.getString(R.string.format_notification), desc, Utility.formatTemperature(context, high), Utility.formatTemperature(context, low));
// NotificationCompatBuilder is a very convenient way to build backward-compatible
// notifications. Just throw in some data.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext()).setColor(resources.getColor(R.color.sunshine_light_blue)).setSmallIcon(iconId).setLargeIcon(largeIcon).setContentTitle(title).setContentText(contentText);
// Make something interesting happen when the user clicks on the notification.
// In this case, opening the app is sufficient.
Intent resultIntent = new Intent(context, MainActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
// WEATHER_NOTIFICATION_ID allows you to update the notification later on.
mNotificationManager.notify(WEATHER_NOTIFICATION_ID, mBuilder.build());
//refreshing last sync
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(lastNotificationKey, System.currentTimeMillis());
editor.commit();
}
cursor.close();
}
}
}
use of android.app.NotificationManager in project AisenWeiBo by wangdan.
the class Notifier method cancelAll.
public static final void cancelAll() {
NotificationManager notificationManager = (NotificationManager) GlobalContext.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(PublishCommentNotificationRequest);
notificationManager.cancel(PublishStatusNotificationRequest);
notificationManager.cancel(ReplyCommentNotificationRequest);
notificationManager.cancel(RepostStatusNotificationRequest);
notificationManager.cancel(RemindUnreadComments);
notificationManager.cancel(RemindUnreadForMentionComments);
notificationManager.cancel(RemindUnreadForMentionStatus);
notificationManager.cancel(RemindUnreadForFollowers);
notificationManager.cancel(RemindUnreadForDM);
}
use of android.app.NotificationManager in project WordPress-Android by wordpress-mobile.
the class SystemServiceFactoryTest method get.
public Object get(Context context, String name) {
System.setProperty("dexmaker.dexcache", context.getCacheDir().getPath());
if (Context.NOTIFICATION_SERVICE.equals(name)) {
NotificationManager notificationManager = mock(NotificationManager.class);
if (sNotificationCallback != null) {
doAnswer(sNotificationCallback).when(notificationManager).notify(anyInt(), any(Notification.class));
doAnswer(sNotificationCallback).when(notificationManager).cancel(anyInt());
}
return notificationManager;
} else {
AppLog.e(T.TESTS, "SystemService:" + name + "No supported in SystemServiceFactoryTest");
}
return null;
}
use of android.app.NotificationManager in project WordPress-Android by wordpress-mobile.
the class ShareAndDismissNotificationReceiver method onReceive.
public void onReceive(Context context, Intent receivedIntent) {
// Cancel (dismiss) the notification
int notificationId = receivedIntent.getIntExtra(NOTIFICATION_ID_KEY, 0);
NotificationManager notificationManager = (NotificationManager) SystemServiceFactory.get(context, Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId);
// Close system notification tray
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
// Start the Share action
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, receivedIntent.getStringExtra(Intent.EXTRA_TEXT));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, receivedIntent.getStringExtra(Intent.EXTRA_SUBJECT));
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(shareIntent);
}
Aggregations