Java Code Examples for android.support.v4.app.NotificationManagerCompat
The following examples show how to use
android.support.v4.app.NotificationManagerCompat.
These examples are extracted from open source projects.
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 Project: SEAL-Demo Author: microsoft File: SyncDataService.java License: 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 #2
Source Project: Small Author: wequick File: NotifyResultActivity.java License: 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 Project: carstream-android-auto Author: thekirankumar File: MediaNotificationManager.java License: 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 #4
Source Project: wearable Author: JimSeker File: MainActivity.java License: 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 #5
Source Project: SuntimesWidget Author: forrestguice File: AlarmNotifications.java License: 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 Project: rcloneExplorer Author: kaczmarkiewiczp File: FirebaseMessagingService.java License: 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 Project: blade-player Author: Valou3433 File: PlayerNotification.java License: 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 Project: Wrox-ProfessionalAndroid-4E Author: retomeier File: LifeformDetectedReceiver.java License: 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 Project: KUAS-AP-Material Author: NKUST-ITC File: NotificationHelper.java License: 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 Project: OsmGo Author: DoFabien File: LocalNotificationManager.java License: 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 Project: three-things-today Author: stephenmcgruer File: NotificationIntentService.java License: 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 Project: share-to-delete Author: heruoxin File: AutoCleanService.java License: 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 Project: AndroidProgramming3e Author: rsippl File: NotificationReceiver.java License: 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 Project: Silence Author: SilenceIM File: MarkReadReceiver.java License: 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 #15
Source Project: AndroidDemoProjects Author: PaulTR File: IterationActivity.java License: 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 #16
Source Project: custom-tabs-client Author: GoogleChrome File: TrustedWebActivityService.java License: 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 Project: YTPlayer Author: KaustubhPatange File: SongBroadCast.java License: 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 #18
Source Project: TelePlus-Android Author: TelePlusDev File: VoIPService.java License: GNU General Public License v2.0 | 5 votes |
protected void startRinging() { if(currentState==STATE_WAITING_INCOMING){ return; } if(USE_CONNECTION_SERVICE && systemCallConnection!=null) systemCallConnection.setRinging(); if (BuildVars.LOGS_ENABLED) { FileLog.d("starting ringing for call " + call.id); } dispatchStateChanged(STATE_WAITING_INCOMING); startRingtoneAndVibration(user.id); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode() && NotificationManagerCompat.from(this).areNotificationsEnabled()) { showIncomingNotification(ContactsController.formatName(user.first_name, user.last_name), null, user, null, 0, VoIPActivity.class); if (BuildVars.LOGS_ENABLED) { FileLog.d("Showing incoming call notification"); } } else { if (BuildVars.LOGS_ENABLED) { FileLog.d("Starting incall activity for incoming call"); } try { PendingIntent.getActivity(VoIPService.this, 12345, new Intent(VoIPService.this, VoIPActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0).send(); } catch (Exception x) { if (BuildVars.LOGS_ENABLED) { FileLog.e("Error starting incall activity", x); } } if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ showNotification(); } } }
Example #19
Source Project: TelePlus-Android Author: TelePlusDev File: VoIPService.java License: 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 #20
Source Project: xDrip Author: NightscoutFoundation File: ActivityRecognizedService.java License: GNU General Public License v3.0 | 5 votes |
private void raise_vehicle_notification(String msg) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentText(msg); builder.setSmallIcon(R.drawable.ic_launcher); if (VehicleMode.shouldPlaySound()) { setInternalPrefsLong(VEHICLE_MODE_LAST_ALERT, JoH.tsl()); builder.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.labbed_musical_chime)); } builder.setContentTitle(getString(R.string.app_name) + " " + "Vehicle mode"); cancel_vehicle_notification(); NotificationManagerCompat.from(this).notify(VEHICLE_NOTIFICATION_ID, builder.build()); }
Example #21
Source Project: nitroshare-android Author: nitroshare File: TransferNotificationManager.java License: MIT License | 5 votes |
/** * Create a notification manager for the specified service * @param service service to manage */ TransferNotificationManager(Service service) { mService = service; mSettings = new Settings(service); mNotificationManager = (NotificationManager) mService.getSystemService( Service.NOTIFICATION_SERVICE); // Android O requires the notification channels to be created if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createChannel(SERVICE_CHANNEL_ID, R.string.channel_service_name, NotificationManager.IMPORTANCE_MIN, false); createChannel(TRANSFER_CHANNEL_ID, R.string.channel_transfer_name, NotificationManager.IMPORTANCE_LOW, false); createChannel(NOTIFICATION_CHANNEL_ID, R.string.channel_notification_name, NotificationManager.IMPORTANCE_DEFAULT, true); } // Create the intent for opening the main activity mIntent = PendingIntent.getActivity( mService, 0, new Intent(mService, TransferActivity.class), 0 ); // Create the builder mBuilder = createBuilder(SERVICE_CHANNEL_ID) .setContentIntent(mIntent) .setContentTitle(mService.getString(R.string.service_transfer_server_title)) .setSmallIcon(R.drawable.ic_stat_transfer); // Set the priority if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mBuilder.setPriority(NotificationManagerCompat.IMPORTANCE_MIN); } else { mBuilder.setPriority(NotificationCompat.PRIORITY_MIN); } }
Example #22
Source Project: android-sdk Author: sensorberg File: SensorbergReceiver.java License: MIT License | 5 votes |
public static void showNotification(Context context, int id, String title, String content, Uri uri, Action action) { if (NotificationManagerCompat.from(context).areNotificationsEnabled()) { Intent intent = new Intent(context, MainActivity.class); intent.putExtra("conversion", action.getInstanceUuid()); PendingIntent openApplicationWithAction = PendingIntent.getActivity( context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(context, OREO_NOTIFICATION_CHANNEL) .setContentIntent(openApplicationWithAction) .setContentTitle(title) .setContentText(content) .setSmallIcon(R.drawable.ic_beacon) .setAutoCancel(true) .setShowWhen(true) .build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notification); SensorbergSdk.notifyConversionStatus(context, action.getInstanceUuid(), Conversion.NOTIFICATION_SHOWN); } else { SensorbergSdk.notifyConversionStatus(context, action.getInstanceUuid(), Conversion.NOTIFICATION_DISABLED); } }
Example #23
Source Project: wear Author: ezhuk File: NotificationUtils.java License: MIT License | 5 votes |
public static void showGroupNotifications(Context context, String group) { Notification first = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.page1_title)) .setContentText(context.getString(R.string.page1_text)) .setGroup(group) .build(); Notification second = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.page2_title)) .setContentText(context.getString(R.string.page2_text)) .setGroup(group) .build(); Notification summary = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.summary_title)) .setContentText(context.getString(R.string.summary_text)) .setGroup(group) .setGroupSummary(true) .build(); NotificationManagerCompat.from(context).notify(getNewID(), first); NotificationManagerCompat.from(context).notify(getNewID(), second); NotificationManagerCompat.from(context).notify(getNewID(), summary); }
Example #24
Source Project: Android-RemoteController Author: YoungBill File: RemoteControllerActivity.java License: Apache License 2.0 | 5 votes |
/** * 是否已经授予通知相关权限 * * @param context,上下文对象 * @return */ private boolean isNotificationListenerServiceEnabled(Context context) { Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context); if (packageNames.contains(context.getPackageName())) { return true; } return false; }
Example #25
Source Project: EasyNLU Author: kolloldas File: ReminderReceiver.java License: Apache License 2.0 | 5 votes |
void showNotification(int id, String text, Context context){ NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ReminderScheduler.CHANNEL_ID) .setSmallIcon(R.drawable.ic_alarm_black_24dp) .setContentTitle("Reminder") .setContentText(text + "!") .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setPriority(NotificationCompat.PRIORITY_HIGH); //.setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(id, builder.build()); }
Example #26
Source Project: NightWatch Author: StephenBlackWasAlreadyTaken File: Notifications.java License: 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 #27
Source Project: rcloneExplorer Author: kaczmarkiewiczp File: DownloadService.java License: MIT License | 5 votes |
private void updateNotification(FileItem downloadItem, 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, DownloadService.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0); Intent cancelIntent = new Intent(this, DownloadCancelAction.class); PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_download) .setContentTitle(downloadItem.getName()) .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 #28
Source Project: io2015-codelabs Author: googlesamples File: MessageReadReceiver.java License: Apache License 2.0 | 5 votes |
@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); } }
Example #29
Source Project: rcloneExplorer Author: kaczmarkiewiczp File: DownloadService.java License: MIT License | 5 votes |
private void createSummaryNotificationForFinished() { Notification summaryNotification = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(getString(R.string.download_complete)) //set content text to support devices running API level < 24 .setContentText(getString(R.string.download_complete)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(DOWNLOAD_FINISHED_GROUP) .setGroupSummary(true) .setAutoCancel(true) .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, summaryNotification); }
Example #30
Source Project: rcloneExplorer Author: kaczmarkiewiczp File: DownloadService.java License: MIT License | 5 votes |
private void showDownloadFailedNotification(int notificationId, String contentText) { createSummaryNotificationForFailed(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(getString(R.string.download_failed)) .setContentText(contentText) .setGroup(DOWNLOAD_FAILED_GROUP) .setPriority(NotificationCompat.PRIORITY_LOW); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId, builder.build()); }