List of usage examples for android.support.v4.app NotificationManagerCompat from
public static NotificationManagerCompat from(Context context)
From source file:com.antonioleiva.materialeverywhere.HomeActivity1.java
public void Notification_Vibration() { long[] vibrationPattern = { 0, 500, 0, 30 }; NotificationManager notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notifier.cancel(RECIPE_NOTIFICATION_ID); //step6/*ww w . ja va 2s. c o m*/ Notification fourthPage = new NotificationCompat.Builder(this).setContentTitle("Step 6") .setContentText(" ? .") .extend(new NotificationCompat.WearableExtender().setContentIcon(R.drawable.ic_launcher) .setContentIconGravity(Gravity.CENTER)) .build(); NotificationCompat.WearableExtender wearableOptions = new NotificationCompat.WearableExtender() .setContentIcon(R.drawable.ic_launcher).setContentIconGravity(Gravity.CENTER).addPage(fourthPage); Notification notification1 = new NotificationCompat.Builder(this).setContentTitle("? ") .setContentText("? ").setSmallIcon(R.drawable.ic_launcher) .setVibrate(vibrationPattern).extend(wearableOptions).build(); NotificationManagerCompat.from(this).notify(FINISH_STEP, notification1); }
From source file:org.chromium.chrome.browser.download.DownloadManagerDelegate.java
/** * @see android.app.DownloadManager#addCompletedDownload(String, String, boolean, String, * String, long, boolean)//from w w w .j a v a 2s . c o m */ protected long addCompletedDownload(String fileName, String description, String mimeType, String path, long length, String originalUrl, String referer, String downloadGuid) { DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext); boolean useSystemNotification = !notificationManager.areNotificationsEnabled(); long downloadId = -1; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { Class<?> c = manager.getClass(); try { Class[] args = { String.class, String.class, boolean.class, String.class, String.class, long.class, boolean.class, Uri.class, Uri.class }; Method method = c.getMethod("addCompletedDownload", args); Uri originalUri = Uri.parse(originalUrl); Uri refererUri = referer == null ? Uri.EMPTY : Uri.parse(referer); downloadId = (Long) method.invoke(manager, fileName, description, true, mimeType, path, length, useSystemNotification, originalUri, refererUri); } catch (SecurityException e) { Log.e(TAG, "Cannot access the needed method."); } catch (NoSuchMethodException e) { Log.e(TAG, "Cannot find the needed method."); } catch (InvocationTargetException e) { Log.e(TAG, "Error calling the needed method."); } catch (IllegalAccessException e) { Log.e(TAG, "Error accessing the needed method."); } } else { downloadId = manager.addCompletedDownload(fileName, description, true, mimeType, path, length, useSystemNotification); } addDownloadIdMapping(downloadId, downloadGuid); return downloadId; }
From source file:com.g11x.checklistapp.ChecklistAppReceiver.java
@Override public void onReceive(Context context, Intent intent) { // super.onReceive(context, intent); // for (String key : intent.getExtras().keySet()) { // Log.d("BLERG", key + ": " + intent.getExtras().get(key).toString() + "(" + intent.getExtras().get(key).getClass().toString()); // }/*from w w w. j a v a 2 s. com*/ Object titleObject = intent.getExtras().get("gcm.notification.title"); String title = titleObject != null ? titleObject.toString() : "RST Announcement"; Object bodyObject = intent.getExtras().get("gcm.notification.body"); String body; if (bodyObject == null) { return; } else { body = bodyObject.toString(); } Object sentTimeObject = intent.getExtras().get("google.sent_time"); Long sentTime = sentTimeObject != null ? (Long) sentTimeObject : System.currentTimeMillis(); ContentValues newValues = new ContentValues(); newValues.put(Database.Notification.MESSAGE_COLUMN, body); newValues.put(Database.Notification.READ_COLUMN, false); newValues.put(Database.Notification.SENT_TIME, sentTime); if (title != null && !title.isEmpty()) { newValues.put(Database.Notification.TITLE_COLUMN, title); } context.getContentResolver().insert(Database.Notification.CONTENT_URI, newValues); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(body).setAutoCancel(true); Intent resultIntent = new Intent(context, NotificationListActivity.class); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addParentStack(NotificationListActivity.class); taskStackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.example.android.supportv4.media.MediaNotificationManager.java
public MediaNotificationManager(MediaBrowserServiceSupport service) { mService = service;/*from w ww .j a v a 2 s .co m*/ updateSessionToken(); mNotificationColor = ResourceHelper.getThemeColor(mService, android.R.attr.colorPrimary, Color.DKGRAY); mNotificationManager = NotificationManagerCompat.from(mService); String pkg = mService.getPackageName(); mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); // Cancel all notifications to handle the case where the Service was killed and // restarted by the system. mNotificationManager.cancelAll(); }
From source file:org.runnerup.service.ListenerService.java
private void dismissNotification() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); notificationManagerCompat.cancel(notificationId); }
From source file:kr.wdream.storyshop.VideoEncodingService.java
public int onStartCommand(Intent intent, int flags, int startId) { path = intent.getStringExtra("path"); boolean isGif = intent.getBooleanExtra("gif", false); if (path == null) { stopSelf();/*from w w w . ja v a 2s . c o m*/ return Service.START_NOT_STICKY; } FileLog.e("tmessages", "start video service"); if (builder == null) { builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext); builder.setSmallIcon(android.R.drawable.stat_sys_upload); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName)); if (isGif) { builder.setTicker(LocaleController.getString("SendingGif", R.string.SendingGif)); builder.setContentText(LocaleController.getString("SendingGif", R.string.SendingGif)); } else { builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo)); builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo)); } } currentProgress = 0; builder.setProgress(100, currentProgress, currentProgress == 0); startForeground(4, builder.build()); NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build()); return Service.START_NOT_STICKY; }
From source file:com.gelakinetic.mtgfam.helpers.updaters.DbUpdaterService.java
/** * When the service is created, set up the notification manager and the actual notification *///from w w w. java 2 s. c om @Override public void onCreate() { super.onCreate(); mHandler = new Handler(); mNotificationManager = NotificationManagerCompat.from(this); Intent intent = new Intent(this, FamiliarActivity.class); PendingIntent mNotificationIntent = PendingIntent.getActivity(this, 0, intent, 0); mBuilder = new NotificationCompat.Builder(this.getApplicationContext()); mBuilder.setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.update_notification)).setSmallIcon(R.drawable.notification_icon) .setContentIntent(mNotificationIntent).setWhen(System.currentTimeMillis()).setOngoing(true) .setOnlyAlertOnce(true); }
From source file:eu.faircode.adblocker.Receiver.java
@Override public void onReceive(final Context context, Intent intent) { Log.i(TAG, "Received " + intent); Util.logExtras(intent);/* w w w . j av a 2s . c om*/ if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { // Application added if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // Show notification if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) { int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); notifyNewApplication(uid, context); } } } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Application removed Rule.clearCache(context); if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { // Remove settings String packageName = intent.getData().getSchemeSpecificPart(); Log.i(TAG, "Deleting settings package=" + packageName); context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply(); int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); if (uid > 0) { NotificationManagerCompat.from(context).cancel(uid); // installed notification NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification } } } else { // Upgrade settings upgrade(true, context); // Start service SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false)) ServiceSinkhole.start("receiver", context); } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false)) ServiceSinkhole.start("receiver", context); else if (prefs.getBoolean("show_stats", false)) ServiceSinkhole.run("receiver", context); } } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, context); } if (Util.isInteractive(context)) ServiceSinkhole.reloadStats("receiver", context); } }
From source file:nuclei.media.MediaNotificationManager.java
public MediaNotificationManager(MediaService service) throws RemoteException { mService = service;/* w w w. j a va 2 s . co m*/ updateSessionToken(); mNotificationColor = ViewUtil.getThemeAttrColor(mService, R.attr.colorPrimary); mNotificationManager = NotificationManagerCompat.from(service); String pkg = mService.getPackageName(); mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mStopCastIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_STOP_CASTING).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mCancelIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_CANCEL).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); // Cancel all notifications to handle the case where the Service was killed and // restarted by the system. mNotificationManager.cancelAll(); }
From source file:cordova.plugins.Diagnostic_Notifications.java
public boolean isRemoteNotificationsEnabled() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat .from(this.cordova.getActivity().getApplicationContext()); boolean result = notificationManagerCompat.areNotificationsEnabled(); return result; }