@Override public void onReceive(Context context, Intent intent) { Intent intent2 = new Intent(context, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setAutoCancel(true) //Automatically delete the notification .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon .setContentIntent(pendingIntent) .setContentTitle("Time to hydrate") .setContentText("Drink a glass of water now") .setCategory(Notification.CATEGORY_REMINDER) .setPriority(Notification.PRIORITY_HIGH) .setSound(defaultSoundUri); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build()); Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show(); }
private void sendNotification(String title, String content) { // this intent will open the activity when the user taps the "open" action on the notification Intent viewIntent = new Intent(this, MainActivity.class); PendingIntent pendingViewIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); // this intent will be sent when the user swipes the notification to dismiss it Intent dismissIntent = new Intent(ZabbkitConstants.NOTIFICATION_DISMISS); PendingIntent pendingDeleteIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(title) .setContentText(content) .setGroup(GROUP_KEY) .setDeleteIntent(pendingDeleteIntent) .setContentIntent(pendingViewIntent); Notification notification = builder.build(); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); notificationManagerCompat.notify(notificationId++, notification); }
@Override protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) { if (!HEARD_ACTION.equals(intent.getAction())) return; final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA); if (threadIds != null) { int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1); NotificationManagerCompat.from(context).cancel(notificationId); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>(); for (long threadId : threadIds) { Log.i(TAG, "Marking meassage as read: " + threadId); List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); messageIdsCollection.addAll(messageIds); } MessageNotifier.updateNotification(context, masterSecret); MarkReadReceiver.process(context, messageIdsCollection); return null; } }.execute(); } }
private void setupUI() { if (NotificationManagerCompat.from(this).areNotificationsEnabled()) { llSettingsEnableNotifications.setVisibility(View.GONE); llSettingsNotifications.setVisibility(View.VISIBLE); } else { llSettingsEnableNotifications.setVisibility(View.VISIBLE); llSettingsNotifications.setVisibility(View.GONE); } swSettingsSounds.setChecked(DCSoundManager.getInstance().isSoundEnabled()); swSettingsMusic.setChecked(DCSoundManager.getInstance().isMusicEnabled()); swSettingsVoice.setChecked(DCSoundManager.getInstance().isVoiceFemale()); swSettingsDailyBrushing.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.DAILY_BRUSHING, false)); swSettingsChangeBrush.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.CHANGE_BRUSH, false)); swSettingsVisitDentist.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.VISIT_DENTIST, false)); swSettingsReminderToVisit.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.REMINDER_TO_VISIT, false)); swSettingsHealthyHabits.setChecked(!DCSharedPreferences.getBoolean(DCSharedPreferences.DCSharedKey.HEALTHY_HABIT, false)); swSettingsEnableNotifications.setChecked(false); }
@Override protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) { if (!CLEAR_ACTION.equals(intent.getAction())) return; final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA); if (threadIds != null) { NotificationManagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1)); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>(); for (long threadId : threadIds) { Log.w(TAG, "Marking as read: " + threadId); List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); messageIdsCollection.addAll(messageIds); } process(context, messageIdsCollection); MessageNotifier.updateNotification(context, masterSecret); return null; } }.execute(); } }
@Override protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) { if (!HEARD_ACTION.equals(intent.getAction())) return; final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA); if (threadIds != null) { int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1); NotificationManagerCompat.from(context).cancel(notificationId); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>(); for (long threadId : threadIds) { Log.i(TAG, "Marking meassage as read: " + threadId); List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId); messageIdsCollection.addAll(messageIds); } MessageNotifier.updateNotification(context, masterSecret); MarkReadReceiver.process(context, messageIdsCollection); return null; } }.execute(); } }
@Override public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.FileUploadProgressChanged) { String fileName = (String)args[0]; if (path != null && path.equals(fileName)) { Float progress = (Float) args[1]; Boolean enc = (Boolean) args[2]; currentProgress = (int)(progress * 100); builder.setProgress(100, currentProgress, currentProgress == 0); NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build()); } } else if (id == NotificationCenter.stopEncodingService) { String filepath = (String)args[0]; if (filepath == null || filepath.equals(path)) { stopSelf(); } } }
public int onStartCommand(Intent intent, int flags, int startId) { path = intent.getStringExtra("path"); if (path == null) { stopSelf(); 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)); 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; }
public void hasPermission(final CallbackContext callbackContext) { mFirebase.cordova.getThreadPool().execute(new Runnable() { public void run() { try { Log.i(TAG, "Checking permission"); Context context = mFirebase.cordova.getActivity(); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled(); JSONObject object = new JSONObject(); object.put("isEnabled", areNotificationsEnabled); callbackContext.success(object); } catch (Exception e) { Log.e(TAG, "Error checking permission"); callbackContext.error(e.getMessage()); } } }); }
public static void showNotification(Context context, String tickertext, String contentText, @DrawableRes int drawable_id, boolean auto_cancel) { int NOTIFICATION_ID = 1; Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND); PendingIntent contentIntent = PendingIntent.getActivity( context, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), drawable_id); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(drawable_id) .setLargeIcon(largeIcon) .setTicker(tickertext) .setContentTitle(context.getResources().getString(R.string.main_app_name)) .setContentText(contentText) .setOngoing(true) .setAutoCancel(auto_cancel) .setContentIntent(contentIntent) .build(); NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification); }
private void showServiceSucceedNotification(String userId, ApplyPremiumAccountResult applyPremiumAccountResult) { Intent intent = new Intent(this, ResultActivity.class); intent.putExtra(EXTRA_USER_ID, userId); intent.putExtra(EXTRA_APPLY_PREMIUM_ACCOUNT_RESULT, applyPremiumAccountResult); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext(), GROUP_ID) .setSmallIcon(R.drawable.ic_request_done_small) .setContentTitle(getString(R.string.notification_your_request_is_done)) .setContentText(getString(R.string.notification_click_here_to_resume_the_app)) .setTicker(getString(R.string.notification_registered)) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setPriority(Notification.PRIORITY_HIGH) .setContentIntent(pendingIntent) .build(); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID_RESULT, notification); }
private void showServiceFailedNotification(String userId) { Intent intent = new Intent(this, ApplyAccountActivity.class); intent.putExtra(EXTRA_USER_ID, userId); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext(), GROUP_ID) .setSmallIcon(R.drawable.ic_request_failed_small) .setContentTitle(getString(R.string.notification_your_request_has_been_denied)) .setContentText(getString(R.string.notification_click_here_to_try_again_in_the_app)) .setTicker(getString(R.string.notification_request_failed)) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setPriority(Notification.PRIORITY_HIGH) .setContentIntent(pendingIntent) .build(); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID_RESULT, notification); }
private void showDisabledNotification() { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_error_white_24dp) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_revoked)) .setContentIntent(pi) .setColor(tv.data) .setOngoing(false) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET); } NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_revoked)); NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build()); }
private void showAutoStartNotification() { Intent main = new Intent(this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_APPROVE, true); PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_error_white_24dp) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_autostart)) .setContentIntent(pi) .setColor(tv.data) .setOngoing(false) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET); } NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_autostart)); NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build()); }
private void showUpdateNotification(String name, String url) { Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_update)) .setContentIntent(pi) .setColor(tv.data) .setOngoing(false) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET); } NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_update)); notification.setSummaryText(name); NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, notification.build()); }
private void refreshNotificationAndForegroundStatus(int playbackState) { switch (playbackState) { case PlaybackStateCompat.STATE_PLAYING: { startForeground(NOTIFICATION_ID, getNotification(playbackState)); break; } case PlaybackStateCompat.STATE_PAUSED: { NotificationManagerCompat.from(PlayerService.this).notify(NOTIFICATION_ID, getNotification(playbackState)); stopForeground(false); break; } default: { stopForeground(true); break; } } }
@Override protected void onHandleIntent(Intent intent) { // TODO(smcgruer): Skip if today is already done. NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setAutoCancel(true) .setContentTitle("Three Things Today") .setContentText("Record what happened today!") .setDefaults(NotificationCompat.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_stat_name); Intent notifyIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity( this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Notification notificationCompat = builder.build(); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this); managerCompat.notify(NOTIFICATION_ID, notificationCompat); }
public MediaNotificationManager(AudioPlayerService service) throws RemoteException { mService = service; updateSessionToken(); 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); // Cancel all notifications to handle the case where the Service was killed and // restarted by the system. mNotificationManager.cancelAll(); }
public void setOpened(Context context, boolean opened) { synchronized (this) { mOpened = opened; if (mOpened) { mMessages.clear(); int prevCount = mUnreadMessageCount; mUnreadMessageCount = 0; NotificationManager.getInstance().callUnreadMessageCountCallbacks(mConnection, mChannel, 0, prevCount); mStorage.requestResetChannelCounter(mConnection.getUUID(), getChannel()); // cancel the notification NotificationManagerCompat.from(context).cancel(mNotificationId); } } NotificationManager.getInstance().updateSummaryNotification(context); }
@Override public void onReceive(Context c, Intent i) { Log.i(TAG, "received result: " + getResultCode()); if (getResultCode() != Activity.RESULT_OK) { // A foreground activity cancelled the broadcast return; } int requestCode = i.getIntExtra(PollService.REQUEST_CODE, 0); Notification notification = (Notification) i.getParcelableExtra(PollService.NOTIFICATION); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(c); notificationManager.notify(requestCode, notification); }
NotificationController(Context context, NotificationManagerCompat notificationManager) { this.context = context; this.notificationManager = notificationManager; NotificationActionCreator actionBuilder = new NotificationActionCreator(context); certificateErrorNotifications = new CertificateErrorNotifications(this); authenticationErrorNotifications = new AuthenticationErrorNotifications(this); syncNotifications = new SyncNotifications(this, actionBuilder); sendFailedNotifications = new SendFailedNotifications(this, actionBuilder); newMailNotifications = NewMailNotifications.newInstance(this, actionBuilder); }
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager, Builder builder) { NotificationController controller = mock(NotificationController.class); when(controller.getContext()).thenReturn(RuntimeEnvironment.application); when(controller.getNotificationManager()).thenReturn(notificationManager); when(controller.createNotificationBuilder()).thenReturn(builder); when(controller.getAccountName(any(Account.class))).thenReturn(ACCOUNT_NAME); return controller; }
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager, NotificationCompat.Builder builder) { NotificationController controller = mock(NotificationController.class); when(controller.getContext()).thenReturn(RuntimeEnvironment.application); when(controller.getNotificationManager()).thenReturn(notificationManager); when(controller.createNotificationBuilder()).thenReturn(builder); return controller; }
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager, Builder builder) { NotificationController controller = mock(NotificationController.class); when(controller.getContext()).thenReturn(RuntimeEnvironment.application); when(controller.getNotificationManager()).thenReturn(notificationManager); when(controller.createNotificationBuilder()).thenReturn(builder); return controller; }
@Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive called"); int conversationId = intent.getIntExtra(CONVERSATION_ID, -1); if (conversationId != -1) { Log.d(TAG, "Conversation " + conversationId + " was read"); NotificationManagerCompat.from(context).cancel(conversationId); } }
public static void showNewPostNotifications(){ if (!Prefs.NotificationsEnabled()){ return; } notificationPosts = PostRepository.getUnSeen(); android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle(); for(Post post : notificationPosts){ inboxStyle.addLine(post.getTitle()); } //Notification sound SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext()); String strRingtonePreference = preference.getString("notifications_new_message_ringtone", "DEFAULT_SOUND"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(App.getAppContext()); mBuilder.setSmallIcon(R.drawable.ic_notifications) .setColor(App.getAppContext().getResources().getColor(R.color.brandColor)) .setSound(Uri.parse(strRingtonePreference)) .setAutoCancel(true) .setContentTitle("Laravel News") .setContentText(getSummaryMessage()) .setContentIntent(getNotificationIntent()) .setStyle(inboxStyle) .setGroup("LNA_NOTIFICATIONS_GROUP"); //Check the vibrate if(Prefs.NotificationVibrateEnabled()){ mBuilder.setVibrate(new long[] {1000,1000}); } Notification notification = mBuilder.build(); // Issue the group notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(App.getAppContext()); notificationManager.notify(1, notification); }
private static boolean checkNotificationListenerPermission(Activity activity) { Set<String> enabledListeners = NotificationManagerCompat.getEnabledListenerPackages(activity); boolean isAccess = false; if (enabledListeners != null) { isAccess = enabledListeners.contains(activity.getPackageName()); } return isAccess; }
private static void sendMultipleThreadNotification(@NonNull Context context, @NonNull NotificationState notificationState, boolean signal) { MultipleRecipientNotificationBuilder builder = new MultipleRecipientNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context)); List<NotificationItem> notifications = notificationState.getNotifications(); builder.setMessageCount(notificationState.getMessageCount(), notificationState.getThreadCount()); builder.setMostRecentSender(notifications.get(0).getIndividualRecipient()); builder.setGroup(NOTIFICATION_GROUP); long timestamp = notifications.get(0).getTimestamp(); if (timestamp != 0) builder.setWhen(timestamp); builder.addActions(notificationState.getMarkAsReadIntent(context, SUMMARY_NOTIFICATION_ID)); ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size()); while(iterator.hasPrevious()) { NotificationItem item = iterator.previous(); builder.addMessageBody(item.getIndividualRecipient(), item.getText()); } if (signal) { builder.setAlarms(notificationState.getRingtone(), notificationState.getVibrate()); builder.setTicker(notifications.get(0).getIndividualRecipient(), notifications.get(0).getText()); } NotificationManagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID, builder.build()); }
public PlayNotifyManager(Activity activity, IPlayControl control, DBMusicocoController dbController) { this.activity = activity; this.control = control; this.dbController = dbController; this.manager = NotificationManagerCompat.from(activity); this.playNotifyReceiver = new PlayNotifyReceiver(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); editor = sharedPreferences.edit(); title = (EditText)findViewById(R.id.title); content = (EditText)findViewById(R.id.content); manager = NotificationManagerCompat.from(this); setIsChecked(); setIsCheckedBoot(); setCheckedHideIcon(); setCheckedHideNew(); clipBoardMonitor(); Log.d(TAG, "onCreate: "); boolean back = getIntent().getBooleanExtra("moveTaskToBack",false); if(back){ moveTaskToBack(true); //Log.i(TAG, "onCreate: veTaskToBack"); } //当前活动被销毁后再重建时保证调用onNewIntent()方法 onNewIntent(getIntent()); if (!isCheckedHideNew){ notifAddNew(); } }
private void unmute() { if (!mutedCurrently) { return; } mutedCurrently = false; NotificationManagerCompat.from(service).cancel(NOTIFICATION_ID_MUTE_DURATION); handler.removeCallbacksAndMessages(null); if (previousZenMode != 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { service.requestInterruptionFilterSafe(previousZenMode); previousZenMode = 0; } }
public void CreateCameraNotification( int notificationId, @NonNull Class<?> receiverActivity) { if (!_settingsController.IsCameraNotificationEnabled()) { Logger.getInstance().Warning(TAG, "Not allowed to display camera notification!"); return; } Bitmap bitmap = BitmapFactory.decodeResource(_context.getResources(), R.drawable.camera); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setHintHideIcon(true).setBackground(bitmap); RemoteViews remoteViews = new RemoteViews(_context.getPackageName(), R.layout.notification_camera); // Action for button show camera Intent goToSecurityIntent = new Intent(_context, receiverActivity); PendingIntent goToSecurityPendingIntent = PendingIntent.getActivity(_context, 34678743, goToSecurityIntent, 0); NotificationCompat.Action goToSecurityWearAction = new NotificationCompat.Action.Builder(R.drawable.camera, "Go to security", goToSecurityPendingIntent).build(); remoteViews.setOnClickPendingIntent(R.id.goToSecurity, goToSecurityPendingIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(_context); builder.setSmallIcon(R.drawable.camera) .setContentTitle("Camera is active!") .setContentText("Go to security!") .setTicker("") .extend(wearableExtender) .addAction(goToSecurityWearAction); Notification notification = builder.build(); notification.contentView = remoteViews; notification.bigContentView = remoteViews; NotificationManagerCompat notificationManager = NotificationManagerCompat.from(_context); notificationManager.notify(notificationId, notification); }
private void stopStats() { Log.i(TAG, "Stats stop"); stats = false; this.removeMessages(MSG_STATS_UPDATE); if (state == State.stats) { Log.d(TAG, "Stop foreground state=" + state.toString()); stopForeground(true); state = State.none; } else NotificationManagerCompat.from(ServiceSinkhole.this).cancel(NOTIFY_TRAFFIC); }
@Override public void onCreate() { super.onCreate(); notificationManager = NotificationManagerCompat.from(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); } }
@Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Receive result with code - " + getResultCode()); if (getResultCode() != Activity.RESULT_OK){ return; } int reqCode = intent.getIntExtra(IndividualService.REQ_CODE, 0); Notification notification = intent.getParcelableExtra(IndividualService.NOTIFICATION); NotificationManagerCompat compat = NotificationManagerCompat.from(context); compat.notify(reqCode, notification); }
@Override public void onReceive(Context context, Intent intent) { if (getResultCode() != Activity.RESULT_OK) { return; } int requestCode = intent.getIntExtra(UpdateService.CODE_REQUEST, 0); Notification notification = (Notification) intent.getParcelableExtra(UpdateService.NOTIFICATION); NotificationManagerCompat nmc = NotificationManagerCompat.from(context); nmc.notify(requestCode, notification); }
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(); audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) .setOnAudioFocusChangeListener(audioFocusChangeListener) .setAcceptsDelayedFocusGain(false) .setWillPauseWhenDucked(true) .setAudioAttributes(audioAttributes) .build(); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaSession = new MediaSessionCompat(this, "PlayerService"); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mediaSessionCallback); Context appContext = getApplicationContext(); Intent activityIntent = new Intent(appContext, MainActivity.class); mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0)); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class); mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0)); exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(exoPlayerListener); DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null); Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR); this.extractorsFactory = new DefaultExtractorsFactory(); }