final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
public static void dismissNotification(Context ctx, int groupId) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx); notificationManager.cancel(groupId); }
private static void publishNotification(Context ctx, Notification notification, int groupId) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx); notificationManager.notify(groupId, notification); }
/** * 通知発行用のヘルパークラス * @param context * @param tag * @param notificationId * @param notification */ private static void notify(@NonNull final Context context, @Nullable final String tag, final int notificationId, @NonNull final Notification notification) { NotificationManagerCompat.from(context) .notify(tag, notificationId, notification); }
/** * Handles action Dismiss in the provided background thread. */ private void handleActionDismiss() { Log.d(TAG, "handleActionDismiss()"); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID); }
/** * Handles action Dismiss in the provided background thread. */ private void handleActionDismiss() { Log.d(TAG, "handleActionDismiss()"); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID); }
public void cancelNotification(Context context) { boolean updateSummary = false; synchronized (this) { mMessages.clear(); } synchronized (mShowingNotificationLock) { // cancel the notification if (mShowingNotification) { NotificationManagerCompat.from(context).cancel(mNotificationId); mShowingNotification = false; updateSummary = true; } } if (updateSummary) NotificationManager.getInstance().updateSummaryNotification(context, null); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMainRelativeLayout = (RelativeLayout) findViewById(R.id.mainRelativeLayout); mNotificationDetailsTextView = (TextView) findViewById(R.id.notificationDetails); mSpinner = (Spinner) findViewById(R.id.spinner); mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); // Create an ArrayAdapter using the string array and a default spinner layout. ArrayAdapter<CharSequence> adapter = new ArrayAdapter( this, android.R.layout.simple_spinner_item, NOTIFICATION_STYLES); // Specify the layout to use when the list of choices appears. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner. mSpinner.setAdapter(adapter); mSpinner.setOnItemSelectedListener(this); }
public void setOpened(Context context, boolean opened) { boolean updateSummary = false; synchronized (this) { mOpened = opened; if (mOpened) { mMessages.clear(); synchronized (mShowingNotificationLock) { // cancel the notification if (mShowingNotification) { NotificationManagerCompat.from(context).cancel(mNotificationId); mShowingNotification = false; updateSummary = true; } } } } if (updateSummary) NotificationManager.getInstance().updateSummaryNotification(context, null); }
/** * Handles action Snooze in the provided background thread. */ private void handleActionSnooze() { Log.d(TAG, "handleActionSnooze()"); // You could use NotificationManager.getActiveNotifications() if you are targeting SDK 23 // and above, but we are targeting devices with lower SDK API numbers, so we saved the // builder globally and get the notification back to recreate it later. NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithBigTextStyle(); } Notification notification; notification = notificationCompatBuilder.build(); if (notification != null) { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID); try { Thread.sleep(SNOOZE_TIME); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification); } }
/** * Handles action Snooze in the provided background thread. */ private void handleActionSnooze() { Log.d(TAG, "handleActionSnooze()"); // You could use NotificationManager.getActiveNotifications() if you are targeting SDK 23 // and above, but we are targeting devices with lower SDK API numbers, so we saved the // builder globally and get the notification back to recreate it later. NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithBigTextStyle(); } Notification notification; notification = notificationCompatBuilder.build(); if (notification != null) { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID); try { Thread.sleep(SNOOZE_TIME); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } notificationManagerCompat.notify(StandaloneMainActivity.NOTIFICATION_ID, notification); } }
@Override public void onMessageSent() { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext); notificationManager.cancel(mNotificationId); NotificationManager.getInstance().onNotificationDismissed(mContext, mConnection, mChannel); NotificationManager.getInstance().updateSummaryNotification(mContext, null); }
NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, updatedNotification);
NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify( StandaloneMainActivity.NOTIFICATION_ID,
super.onCreate(savedInstanceState); setContentView(R.layout.activity_weather); mManager = NotificationManagerCompat.from(this); preferences = new Prefs(this); toolbar = findViewById(R.id.toolbar);
NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification);
NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(StandaloneMainActivity.NOTIFICATION_ID, notification);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate()"); setContentView(R.layout.activity_main); // Enables Ambient mode. mAmbientController = AmbientMode.attachAmbientSupport(this); mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); mMainFrameLayout = findViewById(R.id.mainFrameLayout); mWearableRecyclerView = findViewById(R.id.recycler_view); // Aligns the first and last items on the list vertically centered on the screen. mWearableRecyclerView.setEdgeItemsCenteringEnabled(true); // Customizes scrolling so items farther away form center are smaller. ScalingScrollLayoutCallback scalingScrollLayoutCallback = new ScalingScrollLayoutCallback(); mWearableRecyclerView.setLayoutManager( new WearableLinearLayoutManager(this, scalingScrollLayoutCallback)); // Improves performance because we know changes in content do not change the layout size of // the RecyclerView. mWearableRecyclerView.setHasFixedSize(true); // Specifies an adapter (see also next example). mCustomRecyclerAdapter = new CustomRecyclerAdapter( NOTIFICATION_STYLES, // Controller passes selected data from the Adapter out to this Activity to trigger // updates in the UI/Notifications. new Controller(this)); mWearableRecyclerView.setAdapter(mCustomRecyclerAdapter); }
Event event = AppDatabase.getInstance(this).getScheduleDao().getEvent(eventId); if (event != null) { NotificationManagerCompat.from(this).notify((int) eventId, buildNotification(event));