android.support.v4.app.NotificationManagerCompat Java Examples
The following examples show how to use
android.support.v4.app.NotificationManagerCompat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
void simpleNoti() { //create the intent to launch the notiactivity, then the pentingintent. Intent viewIntent = new Intent(this, NotiActivity.class); viewIntent.putExtra("NotiID", "Notification ID is " + notificationID); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); //Now create the notification. We must use the NotificationCompat or it will not work on the wearable. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Noti") .setContentText("This is a simple notification") .setContentIntent(viewPendingIntent); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(notificationID, notificationBuilder.build()); notificationID++; }
Example #2
Source File: NotifyResultActivity.java From Small with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pending); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mNotificationId = getIntent().getIntExtra("notification_id", 0); TextView textView = (TextView) findViewById(R.id.notification_id_label); textView.setText(mNotificationId + ""); Button removeButton = (Button) findViewById(R.id.remove_notification_button); removeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NotificationManagerCompat.from(NotifyResultActivity.this).cancel(mNotificationId); } }); }
Example #3
Source File: SyncDataService.java From SEAL-Demo with MIT License | 6 votes |
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (REFRESH_ITEMS_ACTION.equals(action)) { Log.d(TAG, "Refresh items START"); Analytics.trackEvent(TAG + " Refresh run items START"); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID, buildNotification("AsureRun", "Syncing data...", R.drawable.ic_tracking, null)); handleRefreshItems(notificationManager, false); } else if (DELETE_DATA_ON_FIRST_START_ACTION.equals(action)) { Log.d(TAG, "Delete data on first start"); Analytics.trackEvent(TAG + " Delete data on first start"); handleDeleteDataOnFirstStart(); } else if (SEND_ITEM_ACTION.equals(action)) { Log.d(TAG, "Sending data on server"); handleSendDataOnServer(); } } }
Example #4
Source File: MediaNotificationManager.java From carstream-android-auto with Apache License 2.0 | 6 votes |
public MediaNotificationManager(Context context, MediaSessionCompat.Token sessionToken) throws RemoteException { mContext = context; mSessionToken = sessionToken; updateSessionToken(); mNotificationManager = NotificationManagerCompat.from(context); String pkg = context.getPackageName(); mPauseIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPlayIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPreviousIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mNextIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mStopIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_STOP).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mStopCastIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, new Intent(ACTION_STOP_CASTING).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(); }
Example #5
Source File: AlarmNotifications.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
private AlarmDatabaseAdapter.AlarmItemTaskListener onShowState(final Context context) { return new AlarmDatabaseAdapter.AlarmItemTaskListener() { @Override public void onFinished(Boolean result, AlarmClockItem item) { Log.d(TAG, "State Saved (onShow)"); if (item.type == AlarmClockItem.AlarmType.ALARM) { if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) { // when notifications are disabled, fallback to directly starting the fullscreen activity startActivity(getFullscreenIntent(context, item.getUri())); } else { showAlarmPlayingToast(getApplicationContext(), item); context.sendBroadcast(getFullscreenBroadcast(item.getUri())); // update fullscreen activity } } } }; }
Example #6
Source File: FirebaseMessagingService.java From rcloneExplorer with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); setNotificationChannel(); Uri uri = Uri.parse(getString(R.string.app_latest_release_url)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.app_update_notification_title)) .setPriority(NotificationCompat.PRIORITY_LOW) .setContentIntent(pendingIntent) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(33, builder.build()); }
Example #7
Source File: PlayerNotification.java From blade-player with GNU General Public License v3.0 | 6 votes |
PlayerNotification(PlayerService service) { this.mService = service; mNotificationManager = NotificationManagerCompat.from(service); mPlayAction = new NotificationCompat.Action(R.drawable.play_arrow, mService.getString(R.string.play), MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_PLAY)); mPauseAction = new NotificationCompat.Action(R.drawable.pause_notif, mService.getString(R.string.pause), MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_PAUSE)); mNextAction = new NotificationCompat.Action(R.drawable.next_arrow_notif, mService.getString(R.string.next), MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_SKIP_TO_NEXT)); mPrevAction = new NotificationCompat.Action(R.drawable.prev_arrow_notif, mService.getString(R.string.prev), MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)); mNotificationManager.cancelAll(); }
Example #8
Source File: LifeformDetectedReceiver.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { // Get the lifeform details from the intent. String type = intent.getStringExtra(EXTRA_LIFEFORM_NAME); double lat = intent.getDoubleExtra(EXTRA_LATITUDE, Double.NaN); double lng = intent.getDoubleExtra(EXTRA_LONGITUDE, Double.NaN); if (type.equals(FACE_HUGGER)) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_alien) .setContentTitle("Face Hugger Detected") .setContentText(Double.isNaN(lat) || Double.isNaN(lng) ? "Location Unknown" : "Located at " + lat + "," + lng); notificationManager.notify(NOTIFICATION_ID, builder.build()); } }
Example #9
Source File: NotificationHelper.java From KUAS-AP-Material with MIT License | 6 votes |
/** * Create a notification * * @param context The application context * @param title Notification title * @param content Notification content. */ public static void createNotification(final Context context, final String title, final String content, int id) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setColor(ContextCompat.getColor(context, R.color.main_theme)) .extend(new NotificationCompat.WearableExtender() .setHintShowBackgroundOnly(true)).setContentText(content) .setAutoCancel(true).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)) .setSmallIcon(R.drawable.ic_stat_kuas_ap); builder.setVibrate(vibrationPattern); builder.setLights(Color.GREEN, 800, 800); builder.setDefaults(Notification.DEFAULT_SOUND); notificationManager.notify(id, builder.build()); }
Example #10
Source File: LocalNotificationManager.java From OsmGo with MIT License | 6 votes |
@Nullable public JSONArray schedule(PluginCall call, List<LocalNotification> localNotifications) { JSONArray ids = new JSONArray(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); boolean notificationsEnabled = notificationManager.areNotificationsEnabled(); if (!notificationsEnabled) { call.error("Notifications not enabled on this device"); return null; } for (LocalNotification localNotification : localNotifications) { Integer id = localNotification.getId(); if (localNotification.getId() == null) { call.error("LocalNotification missing identifier"); return null; } dismissVisibleNotification(id); cancelTimerForNotification(id); buildNotification(notificationManager, localNotification, call); ids.put(id); } return ids; }
Example #11
Source File: NotificationIntentService.java From three-things-today with Apache License 2.0 | 6 votes |
@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); }
Example #12
Source File: AutoCleanService.java From share-to-delete with GNU General Public License v3.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { context = this; notificationManagerCompat = NotificationManagerCompat.from(context); preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!preferences.getBoolean(AutoCleanSettingsActivity.PREF_AUTO_CLEAN, false)) return false; sendNotification(); cleanUp(); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); new Handler().postDelayed(new Runnable() { @Override public void run() { Log.v(MyUtil.PACKAGE_NAME, getString(R.string.toast_auto_clean, deletedFileCount)); Toast.makeText( context, getString(R.string.toast_auto_clean, deletedFileCount), Toast.LENGTH_SHORT ).show(); notificationManagerCompat.cancel(NOTIFICATION_JOB_ID); } }, 3000); return true; }
Example #13
Source File: NotificationReceiver.java From AndroidProgramming3e with Apache License 2.0 | 6 votes |
@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); }
Example #14
Source File: HomeFragment.java From fitnotifications with Apache License 2.0 | 5 votes |
private void updateNotificationAccessText() { Set<String> EnabledListenerPackagesSet = NotificationManagerCompat. getEnabledListenerPackages(getContext()); if (EnabledListenerPackagesSet.contains(Constants.PACKAGE_NAME) && EnabledListenerPackagesSet.contains(Constants.FITBIT_PACKAGE_NAME)) { mNotificationAccessTV.setText(getString(R.string.notification_access_disable_textView)); } else { mNotificationAccessTV.setText(getString(R.string.notification_access_enable_textView)); } }
Example #15
Source File: MarkReadReceiver.java From Silence with GNU General Public License v3.0 | 5 votes |
@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) { for (long threadId : threadIds) { Log.w(TAG, "Marking as read: " + threadId); DatabaseFactory.getThreadDatabase(context).setRead(threadId); DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId); } MessageNotifier.updateNotification(context, masterSecret); return null; } }.execute(); } }
Example #16
Source File: TrustedWebActivityService.java From custom-tabs-client with Apache License 2.0 | 5 votes |
/** * Displays a notification. * @param platformTag The notification tag, see * {@link NotificationManager#notify(String, int, Notification)}. * @param platformId The notification id, see * {@link NotificationManager#notify(String, int, Notification)}. * @param notification The notification to be displayed, constructed by the provider. * @param channelName The name of the notification channel that the notification should be * displayed on. This method gets or creates a channel from the name and * modifies the notification to use that channel. * @return Whether the notification was successfully displayed (the channel/app may be blocked * by the user). */ protected boolean notifyNotificationWithChannel(String platformTag, int platformId, Notification notification, String channelName) { ensureOnCreateCalled(); if (!NotificationManagerCompat.from(this).areNotificationsEnabled()) return false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String channelId = channelNameToId(channelName); // Create the notification channel, (no-op if already created). mNotificationManager.createNotificationChannel(new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)); // Check that the channel is enabled. if (mNotificationManager.getNotificationChannel(channelId).getImportance() == NotificationManager.IMPORTANCE_NONE) { return false; } // Set our notification to have that channel. Notification.Builder builder = Notification.Builder.recoverBuilder(this, notification); builder.setChannelId(channelId); notification = builder.build(); } mNotificationManager.notify(platformTag, platformId, notification); return true; }
Example #17
Source File: NotificationCenter.java From SightRemote with GNU General Public License v3.0 | 5 votes |
public static void showOngoingNotification(int text) { NotificationCompat.Builder builder = new NotificationCompat.Builder(SightRemote.getInstance(), ONGOING_NOTIFICATION_CHANNEL_ID); builder.setSmallIcon(R.drawable.ic_notification); builder.setContentTitle(SightRemote.getInstance().getString(R.string.sightremote_is_active)); builder.setContentText(SightRemote.getInstance().getString(text)); builder.setPriority(NotificationManagerCompat.IMPORTANCE_MIN); builder.setShowWhen(false); NotificationManagerCompat.from(SightRemote.getInstance()).notify(ONGOING_NOTIFICATION_ID, ongoingNotification = builder.build()); }
Example #18
Source File: IterationActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
private void setupTimer( long duration ) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from( this ); notificationManager.cancel( 1 ); notificationManager.notify( 1, buildNotification( duration ) ); registerAlarmManager(duration); finish(); }
Example #19
Source File: Notify.java From android-ponewheel with MIT License | 5 votes |
public void init(MainActivity mainActivity) { mContext = mainActivity.getApplicationContext(); clearHandler = new Handler(Looper.getMainLooper()); createNotificationChannels(); notifyManager = NotificationManagerCompat.from(mContext); startStatusNotification(); waiting(); }
Example #20
Source File: SongBroadCast.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
public void disableContext(Context context) { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); notificationManagerCompat.cancel(1); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.deleteNotificationChannel("channel_01"); } Process.killProcess(Process.myPid()); }
Example #21
Source File: DeleteService.java From rcloneExplorer with MIT License | 5 votes |
private void createSummaryNotificationForFailed() { Notification summaryNotification = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(getString(R.string.operation_failed)) //set content text to support devices running API level < 24 .setContentText(getString(R.string.operation_failed)) .setSmallIcon(android.R.drawable.stat_sys_warning) .setGroup(OPERATION_FAILED_GROUP) .setGroupSummary(true) .setAutoCancel(true) .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(OPERATION_FAILED_NOTIFICATION_ID, summaryNotification); }
Example #22
Source File: MainActivity.java From android-SkeletonWearableApp with Apache License 2.0 | 5 votes |
/** * Handles the button to launch a notification. */ public void showNotification(View view) { Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_title)) .setSmallIcon(R.drawable.ic_launcher) .addAction(R.drawable.ic_launcher, getText(R.string.action_launch_activity), PendingIntent.getActivity(this, NOTIFICATION_REQUEST_CODE, new Intent(this, GridExampleActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) .build(); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification); finish(); }
Example #23
Source File: VoIPService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public void onUIForegroundStateChanged(boolean isForeground) { if (currentState == STATE_WAITING_INCOMING) { if (isForeground) { stopForeground(true); } else { if (!((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()) { if(NotificationManagerCompat.from(this).areNotificationsEnabled()) showIncomingNotification(ContactsController.formatName(user.first_name, user.last_name), null, user, null, 0, VoIPActivity.class); else declineIncomingCall(DISCARD_REASON_LINE_BUSY, null); } else { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { Intent intent = new Intent(VoIPService.this, VoIPActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); try { PendingIntent.getActivity(VoIPService.this, 0, intent, 0).send(); } catch (PendingIntent.CanceledException e) { if (BuildVars.LOGS_ENABLED) { FileLog.e("error restarting activity", e); } declineIncomingCall(DISCARD_REASON_LINE_BUSY, null); } if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ showNotification(); } } }, 500); } } } }
Example #24
Source File: ToastUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
static IToast makeToast(Context context, CharSequence text, int duration) { if (NotificationManagerCompat.from(context).areNotificationsEnabled()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!UtilsBridge.isGrantedDrawOverlays()) { return new SystemToast(makeNormalToast(context, text, duration)); } } } return new ToastWithoutNotification(makeNormalToast(context, text, duration)); }
Example #25
Source File: UploadService.java From rcloneExplorer with MIT License | 5 votes |
private void updateNotification(String uploadFileName, String content, String[] bigTextArray) { StringBuilder bigText = new StringBuilder(); for (int i = 0; i < bigTextArray.length; i++) { bigText.append(bigTextArray[i]); if (i < 4) { bigText.append("\n"); } } Intent foregroundIntent = new Intent(this, UploadService.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0); Intent cancelIntent = new Intent(this, UploadCancelAction.class); PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_upload) .setContentTitle(uploadFileName) .setContentText(content) .setPriority(NotificationCompat.PRIORITY_LOW) .setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString())) .addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); notificationManagerCompat.notify(PERSISTENT_NOTIFICATION_ID, builder.build()); }
Example #26
Source File: MoveService.java From rcloneExplorer with MIT License | 5 votes |
private void showFailedNotification(String title, String content, int notificationId) { createSummaryNotificationForFailed(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(title) .setContentText(content) .setGroup(OPERATION_FAILED_GROUP) .setPriority(NotificationCompat.PRIORITY_LOW); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId, builder.build()); }
Example #27
Source File: Notifications.java From NightWatch with GNU General Public License v3.0 | 5 votes |
private void bgOngoingNotification(final BgGraphBuilder bgGraphBuilder) { mHandler.post(new Runnable() { @Override public void run() { NotificationManagerCompat .from(mContext) .notify(ongoingNotificationId, createOngoingNotification(bgGraphBuilder, mContext)); if (iconBitmap != null) iconBitmap.recycle(); if (notifiationBitmap != null) notifiationBitmap.recycle(); } }); }
Example #28
Source File: SyncService.java From rcloneExplorer with MIT License | 5 votes |
private void showConnectivityChangedNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(getString(R.string.sync_cancelled)) .setContentText(getString(R.string.wifi_connections_isnt_available)) .setPriority(NotificationCompat.PRIORITY_DEFAULT); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(CONNECTIVITY_CHANGE_NOTIFICATION_ID, builder.build()); }
Example #29
Source File: SyncService.java From rcloneExplorer with MIT License | 5 votes |
private void showFailedNotification(String title, String content, int notificationId) { createSummaryNotificationForFailed(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(title) .setContentText(content) .setGroup(OPERATION_FAILED_GROUP) .setPriority(NotificationCompat.PRIORITY_LOW); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId, builder.build()); }
Example #30
Source File: VoIPService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public void onUIForegroundStateChanged(boolean isForeground) { if (currentState == STATE_WAITING_INCOMING) { if (isForeground) { stopForeground(true); } else { if (!((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()) { if(NotificationManagerCompat.from(this).areNotificationsEnabled()) showIncomingNotification(ContactsController.formatName(user.first_name, user.last_name), null, user, null, 0, VoIPActivity.class); else declineIncomingCall(DISCARD_REASON_LINE_BUSY, null); } else { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { Intent intent = new Intent(VoIPService.this, VoIPActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); try { PendingIntent.getActivity(VoIPService.this, 0, intent, 0).send(); } catch (PendingIntent.CanceledException e) { if (BuildVars.LOGS_ENABLED) { FileLog.e("error restarting activity", e); } declineIncomingCall(DISCARD_REASON_LINE_BUSY, null); } if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ showNotification(); } } }, 500); } } } }