android.app.Notification Java Examples
The following examples show how to use
android.app.Notification.
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: NotificationUtils.java From DeviceConnect-Android with MIT License | 6 votes |
/** * 通知経由でのActivity起動を行う(Pending Intent) * @param context コンテキスト * @param notificationId 通知のID * @param requestCode Activity起動のリクエストコード * @param intent インテント * @param contentText 通知に表示するテキスト */ public static void notify(Context context, int notificationId, int requestCode, Intent intent, String contentText) { NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); if(notificationManager != null) { PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID) .setContentText(contentText) .setContentTitle(NOTIFICATION_CONTENT_TITLE) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_action_labels) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_labels)) .setStyle(new Notification.BigTextStyle().setBigContentTitle(NOTIFICATION_CONTENT_TITLE).bigText(contentText)) .setContentIntent(pendingIntent) .build(); notificationManager.notify(notificationId, notification); } }
Example #2
Source File: BackendlessFCMService.java From Android-SDK with MIT License | 6 votes |
private void handleMessageWithTemplate( final Context context, Intent intent, AndroidPushTemplate androidPushTemplate, final int notificationId ) { Bundle newBundle = PushTemplateHelper.prepareMessageBundle( intent.getExtras(), androidPushTemplate, notificationId ); Intent newMsgIntent = new Intent(); newMsgIntent.putExtras( newBundle ); if( !this.onMessage( context, newMsgIntent ) ) return; if( androidPushTemplate.getContentAvailable() != null && androidPushTemplate.getContentAvailable() == 1 ) return; Notification notification = PushTemplateHelper.convertFromTemplate( context, androidPushTemplate, newBundle, notificationId ); PushTemplateHelper.showNotification( context, notification, androidPushTemplate.getName(), notificationId ); }
Example #3
Source File: NotificationUtils.java From freemp with Apache License 2.0 | 6 votes |
public static Notification getNotification(Context context, PendingIntent pendingIntent, ClsTrack track, boolean isPlaying) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder .setAutoCancel(true) .setSmallIcon(R.drawable.freemp) .setContentTitle(track != null ? track.getArtist() : "") .setContentText(track != null ? track.getTitle() : ""); Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; notification.contentIntent = pendingIntent; if (track != null) { notification.contentView = getNotificationViews(track, context, isPlaying, R.layout.notification); } else { //notification.contentView = null; //notification.setLatestEventInfo(context, "", "", pendingIntent); notification = null; } return notification; }
Example #4
Source File: SendRepostService.java From iBeebo with GNU General Public License v3.0 | 6 votes |
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendRepostService.this) .setTicker(getString(R.string.send_successfully)) .setContentTitle(getString(R.string.send_successfully)).setOnlyAlertOnce(true).setAutoCancel(true) .setSmallIcon(R.drawable.send_successfully).setOngoing(false); Notification notification = builder.getNotification(); final int id = tasksNotifications.get(task); NotificationUtility.show(notification, id); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); LocalBroadcastManager.getInstance(SendRepostService.this).sendBroadcast( new Intent(AppEventAction.buildSendRepostSuccessfullyAction(oriMsg))); }
Example #5
Source File: NotificationService.java From NotificationPeekPort with Apache License 2.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { Notification postedNotification = sbn.getNotification(); if (postedNotification.tickerText == null || sbn.isOngoing() || !sbn.isClearable() || isInBlackList(sbn)) { return; } if (mAppList.isInQuietHour(sbn.getPostTime())) { // The first notification arrived during quiet hour will unregister all sensor listeners. mNotificationPeek.unregisterEventListeners(); return; } mNotificationHub.addNotification(sbn); if (AccessChecker.isDeviceAdminEnabled(this)) { mNotificationPeek .showNotification(sbn, false, mPeekTimeoutMultiplier, mSensorTimeoutMultiplier, mShowContent); } }
Example #6
Source File: ProgressBarController.java From GravityBox with Apache License 2.0 | 6 votes |
private ProgressInfo verifyNotification(StatusBarNotification statusBarNotif) { if (statusBarNotif == null) return null; String id = getIdentifier(statusBarNotif); if (id == null) return null; Notification n = statusBarNotif.getNotification(); if (n != null && (SUPPORTED_PACKAGES.contains(statusBarNotif.getPackageName()) || n.extras.getBoolean(ModLedControl.NOTIF_EXTRA_PROGRESS_TRACKING))) { ProgressInfo pi = getProgressInfo(id, n); if (pi != null && pi.hasProgressBar) return pi; } return null; }
Example #7
Source File: NotificationCompat.java From adt-leanback-support with Apache License 2.0 | 6 votes |
@Override public WearableExtender clone() { WearableExtender that = new WearableExtender(); that.mActions = new ArrayList<Action>(this.mActions); that.mFlags = this.mFlags; that.mDisplayIntent = this.mDisplayIntent; that.mPages = new ArrayList<Notification>(this.mPages); that.mBackground = this.mBackground; that.mContentIcon = this.mContentIcon; that.mContentIconGravity = this.mContentIconGravity; that.mContentActionIndex = this.mContentActionIndex; that.mCustomSizePreset = this.mCustomSizePreset; that.mCustomContentHeight = this.mCustomContentHeight; that.mGravity = this.mGravity; return that; }
Example #8
Source File: NoiseService.java From chromadoze with GNU General Public License v3.0 | 6 votes |
private RemoteViews addButtonToNotification(Notification n) { // Create a new RV with a Stop button. RemoteViews rv = new RemoteViews( getPackageName(), R.layout.notification_with_stop_button); PendingIntent pendingIntent = PendingIntent.getService( this, 0, newStopIntent(this, R.string.stop_reason_notification), PendingIntent.FLAG_CANCEL_CURRENT); rv.setOnClickPendingIntent(R.id.stop_button, pendingIntent); // Pre-render the original RV, and copy some of the colors. RemoteViews oldRV = getContentView(this, n); final View inflated = oldRV.apply(this, new FrameLayout(this)); final TextView titleText = findTextView(inflated, getString(R.string.app_name)); final TextView defaultText = findTextView(inflated, getString(R.string.notification_text)); rv.setInt(R.id.divider, "setBackgroundColor", defaultText.getTextColors().getDefaultColor()); rv.setInt(R.id.stop_button_square, "setBackgroundColor", titleText.getTextColors().getDefaultColor()); // Insert a copy of the original RV into the new one. rv.addView(R.id.notification_insert, oldRV.clone()); return rv; }
Example #9
Source File: Downloaders.java From shortyz with GNU General Public License v3.0 | 6 votes |
private void postDownloadedNotification(int i, String name, File puzFile) { try { String contentTitle = "Downloaded " + name; Intent notificationIntent = new Intent(Intent.ACTION_EDIT, Uri.fromFile(puzFile), context, PlayActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification not = new NotificationCompat.Builder(context, ShortyzApplication.PUZZLE_DOWNLOAD_CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setContentTitle(contentTitle) .setContentText(puzFile.getName()) .setContentIntent(contentIntent) .setWhen(System.currentTimeMillis()) .build(); if (this.notificationManager != null) { this.notificationManager.notify(i, not); } } catch(Exception e){ e.printStackTrace(); } }
Example #10
Source File: NotifyManager.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
private void createBaseNotify(Intent intent, String title, String content, int notifyId) { Notification.Builder builder = getMsgNotificationBuilder().setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(title) .setAutoCancel(true) .setOngoing(false); if (!StringUtils.isEmpty(content)) { builder.setContentText(content); } PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Notification notification = builder.build(); mNotificationManager.notify(notifyId, notification); }
Example #11
Source File: UpdateBookListService.java From a with GNU General Public License v3.0 | 6 votes |
/** * 更新通知 */ private void updateNotification(int state, String msg) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MApplication.channelIdReadAloud) .setSmallIcon(R.drawable.ic_network_check) .setOngoing(true) .setContentTitle(getString(R.string.check_book_source)) .setContentText(msg) .setContentIntent(getActivityPendingIntent()); builder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.cancel), getThisServicePendingIntent()); if (recommendIndexBeanList != null) { builder.setProgress(recommendIndexBeanList.size(), state, false); } builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Notification notification = builder.build(); startForeground(notificationId, notification); }
Example #12
Source File: OnekeyShare.java From Huochexing12306 with Apache License 2.0 | 6 votes |
private void showNotification(long cancelTime, String text) { try { Context app = getContext().getApplicationContext(); NotificationManager nm = (NotificationManager) app .getSystemService(Context.NOTIFICATION_SERVICE); final int id = Integer.MAX_VALUE / 13 + 1; nm.cancel(id); long when = System.currentTimeMillis(); Notification notification = new Notification(notifyIcon, text, when); PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0); notification.setLatestEventInfo(app, notifyTitle, text, pi); notification.flags = Notification.FLAG_AUTO_CANCEL; nm.notify(id, notification); if (cancelTime > 0) { Message msg = new Message(); msg.what = MSG_CANCEL_NOTIFY; msg.obj = nm; msg.arg1 = id; UIHandler.sendMessageDelayed(msg, cancelTime, this); } } catch (Exception e) { e.printStackTrace(); } }
Example #13
Source File: ForegroundServiceStarter.java From xDrip with GNU General Public License v3.0 | 6 votes |
private Notification notification() { Intent intent = new Intent(mContext, Home.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(Home.class); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); NotificationCompat.Builder b=new NotificationCompat.Builder(mService); b.setOngoing(true); b.setCategory(Notification.CATEGORY_SERVICE); // Hide this notification "below the fold" on L+ b.setPriority(Notification.PRIORITY_MIN); // Don't show this notification on the lock screen on L+ b.setVisibility(Notification.VISIBILITY_SECRET); b.setContentTitle("xDrip is Running") .setContentText("xDrip Data collection service is running.") .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on); b.setContentIntent(resultPendingIntent); return(b.build()); }
Example #14
Source File: TriggerTasksService.java From FreezeYou with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) || new AppPreferences(getApplicationContext()).getBoolean("useForegroundService", false)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Notification.Builder mBuilder = new Notification.Builder(this); mBuilder.setSmallIcon(R.drawable.ic_notification); mBuilder.setContentText(getString(R.string.backgroundService)); NotificationChannel channel = new NotificationChannel("BackgroundService", getString(R.string.backgroundService), NotificationManager.IMPORTANCE_NONE); NotificationManager notificationManager = getSystemService(NotificationManager.class); if (notificationManager != null) notificationManager.createNotificationChannel(channel); mBuilder.setChannelId("BackgroundService"); Intent resultIntent = new Intent(getApplicationContext(), Main.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); startForeground(1, mBuilder.build()); } else { startForeground(1, new Notification()); } } }
Example #15
Source File: OverviewFragment.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void onPostExecute(String s) { super.onPostExecute(s); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_kolabnotes_breeze) .setContentTitle(context.getResources().getString(R.string.imported)) .setStyle(new NotificationCompat.BigTextStyle().bigText(s)) .setAutoCancel(true).build(); notificationManager.notify(0, notification); reloadData(); }
Example #16
Source File: DownloadForegroundService.java From VBrowser-Android with GNU General Public License v2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); NotificationManager service = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); String channelId = ""; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { channelId = createNotificationChannel(); } Notification notification = new NotificationCompat.Builder(MainApplication.mainApplication, channelId) .setContentTitle("前台任务") .setContentText("正在下载") .setSmallIcon(R.mipmap.download_default) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.download_default)).build(); startForeground(ONGOING_NOTIFICATION_ID, notification); }
Example #17
Source File: ForegroundService.java From prayer-times-android with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.O) public static Notification createNotification(Context c) { NotificationManager nm = c.getSystemService(NotificationManager.class); String channelId = "foreground"; if (nm.getNotificationChannel(channelId) == null) { nm.createNotificationChannel(new NotificationChannel(channelId, c.getString(R.string.appName), NotificationManager.IMPORTANCE_MIN)); } Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).putExtra(Settings.EXTRA_APP_PACKAGE, c.getPackageName()) .putExtra(Settings.EXTRA_CHANNEL_ID, channelId); PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(c, channelId); builder.setContentIntent(pendingIntent); builder.setSmallIcon(R.drawable.ic_abicon); builder.setContentText(c.getString(R.string.clickToDisableNotification)); builder.setPriority(NotificationCompat.PRIORITY_MIN); builder.setWhen(0); //show as last return builder.build(); }
Example #18
Source File: GeofencingService.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
@Override protected void onHandleIntent( Intent intent ) { NotificationCompat.Builder builder = new NotificationCompat.Builder( this ); builder.setSmallIcon( R.drawable.ic_launcher ); builder.setDefaults( Notification.DEFAULT_ALL ); builder.setOngoing( true ); int transitionType = LocationClient.getGeofenceTransition( intent ); if( transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ) { builder.setContentTitle( "Geofence Transition" ); builder.setContentText( "Entering Geofence" ); mNotificationManager.notify( 1, builder.build() ); } else if( transitionType == Geofence.GEOFENCE_TRANSITION_EXIT ) { builder.setContentTitle( "Geofence Transition" ); builder.setContentText( "Exiting Geofence" ); mNotificationManager.notify( 1, builder.build() ); } }
Example #19
Source File: KeyGeneratorService.java From an2linuxclient with GNU General Public License v3.0 | 6 votes |
@Override protected void onHandleIntent(Intent workIntent) { Intent notificationIntent = new Intent(this, ClientCertificateActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID_GEN) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(getString(R.string.generate_key_working)) .setContentTitle(getString(R.string.generate_key_working_notification)) .setPriority(NotificationCompat.PRIORITY_LOW) .setContentIntent(pendingIntent) .build(); startForeground(NOTIFICATION_ID_GEN, notification); RsaHelper.initialiseRsaKeyAndCert(getApplicationContext()); currentlyGenerating = false; stopForeground(true); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_ACTION)); }
Example #20
Source File: MainActivity.java From splitapkinstall with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.O) public static void createNotificationChannels(Context appCtx) { try { final NotificationManager notificationManager = (NotificationManager) appCtx.getSystemService(Context.NOTIFICATION_SERVICE); // Notification with sound channel CharSequence name = appCtx.getString(R.string.export_notification); String description = appCtx.getString(R.string.export_notification_description); NotificationChannel channel = new NotificationChannel("export_sound", name, NotificationManager.IMPORTANCE_HIGH); channel.setDescription(description); channel.enableVibration(true); channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); notificationManager.createNotificationChannel(channel); } catch (Exception e) { e.printStackTrace(); } }
Example #21
Source File: MasterService.java From 600SeriesAndroidUploader with MIT License | 6 votes |
@TargetApi(26) private synchronized void createNotificationChannels() { NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager == null) { Log.e(TAG, "Could not create notification channels. NotificationManager is null"); stopSelf(); } NotificationChannel statusChannel = new NotificationChannel("status", "Status", NotificationManager.IMPORTANCE_LOW); statusChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); notificationManager.createNotificationChannel(statusChannel); NotificationChannel errorChannel = new NotificationChannel("error", "Errors", NotificationManager.IMPORTANCE_HIGH); errorChannel.enableLights(true); errorChannel.setLightColor(Color.RED); errorChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); notificationManager.createNotificationChannel(errorChannel); }
Example #22
Source File: MediaReaderService.java From AndroidScreenShare with Apache License 2.0 | 6 votes |
private void buildNotification(int resId,String tiile,String contenttext){ NotificationCompat.Builder builder = new NotificationCompat.Builder(this,UNLOCK_NOTIFICATION_CHANNEL_ID); // 必需的通知内容 builder.setContentTitle(tiile) .setContentText(contenttext) .setSmallIcon(resId); Intent notifyIntent = new Intent(this, MediaProjectionActivity.class); PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(notifyPendingIntent); Notification notification = builder.build(); //常驻状态栏的图标 //notification.icon = resId; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中 notification.flags |=Notification.FLAG_ONGOING_EVENT; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用 notification.flags |= Notification.FLAG_NO_CLEAR; NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID_ICON, notification); startForeground(NOTIFICATION_ID_ICON, notification); }
Example #23
Source File: NotifyManager.java From LLApp with Apache License 2.0 | 6 votes |
/** * 折叠式 * * @param context */ public static void shwoNotify(Context context,int flag) { //先设定RemoteViews RemoteViews view_custom = new RemoteViews(context.getPackageName(), R.layout.notification); //设置对应IMAGEVIEW的ID的资源图片 view_custom.setImageViewResource(R.id.image, R.mipmap.ic_launcher); view_custom.setTextViewText(R.id.bbs_type_Title, "今日头条"); view_custom.setTextColor(R.id.text, Color.BLACK); view_custom.setTextViewText(R.id.text, "金州勇士官方宣布球队已经解雇了主帅马克-杰克逊,随后宣布了最后的结果。"); view_custom.setTextColor(R.id.bbs_type_Title, Color.BLACK); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContent(view_custom) .setContentIntent(PendingIntent.getActivity(context, 4, new Intent(context, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT)) .setWhen(System.currentTimeMillis())// 通知产生的时间,会在通知信息里显示 .setTicker("有新资讯") .setPriority(Notification.PRIORITY_HIGH)// 设置该通知优先级 .setOngoing(false)//不是正在进行的 true为正在进行 效果和.flag一样 .setSmallIcon(R.mipmap.ic_launcher); Notification notify = mBuilder.build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); notificationManager.notify(flag, notify); }
Example #24
Source File: ShellService.java From RemoteAdbShell with Apache License 2.0 | 6 votes |
private Notification createNotification(DeviceConnection devConn, boolean connected) { String ticker; String message; if (connected) { ticker = "Connection Established"; message = "Connected to "+getConnectionString(devConn); } else { ticker = "Connection Terminated"; message = "Connection to "+getConnectionString(devConn)+" failed"; } return new NotificationCompat.Builder(getApplicationContext()) .setTicker("Remote ADB Shell - "+ticker) .setSmallIcon(R.drawable.notificationicon) .setOnlyAlertOnce(true) .setOngoing(connected) .setAutoCancel(!connected) .setContentTitle("Remote ADB Shell") .setContentText(message) .setContentIntent(createPendingIntentForConnection(devConn)) .build(); }
Example #25
Source File: PlayingNotification.java From Music-Player with GNU General Public License v3.0 | 6 votes |
void updateNotifyModeAndPostNotification(Notification notification) { int newNotifyMode; if (service.isPlaying()) { newNotifyMode = NOTIFY_MODE_FOREGROUND; } else { newNotifyMode = NOTIFY_MODE_BACKGROUND; } if (notifyMode != newNotifyMode && newNotifyMode == NOTIFY_MODE_BACKGROUND) { service.stopForeground(false); } if (newNotifyMode == NOTIFY_MODE_FOREGROUND) { service.startForeground(NOTIFICATION_ID, notification); } else if (newNotifyMode == NOTIFY_MODE_BACKGROUND) { notificationManager.notify(NOTIFICATION_ID, notification); } notifyMode = newNotifyMode; }
Example #26
Source File: ToolboxApplication.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { DfuServiceInitiator.createDfuNotificationChannel(this); final NotificationChannel channel = new NotificationChannel(CONNECTED_DEVICE_CHANNEL, getString(R.string.channel_connected_devices_title), NotificationManager.IMPORTANCE_LOW); channel.setDescription(getString(R.string.channel_connected_devices_description)); channel.setShowBadge(false); channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); final NotificationChannel fileChannel = new NotificationChannel(FILE_SAVED_CHANNEL, getString(R.string.channel_files_title), NotificationManager.IMPORTANCE_LOW); fileChannel.setDescription(getString(R.string.channel_files_description)); fileChannel.setShowBadge(false); fileChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); final NotificationChannel proximityChannel = new NotificationChannel(PROXIMITY_WARNINGS_CHANNEL, getString(R.string.channel_proximity_warnings_title), NotificationManager.IMPORTANCE_LOW); proximityChannel.setDescription(getString(R.string.channel_proximity_warnings_description)); proximityChannel.setShowBadge(false); proximityChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(fileChannel); notificationManager.createNotificationChannel(proximityChannel); } }
Example #27
Source File: NotificationUtils.java From YCNotification with Apache License 2.0 | 5 votes |
/** * 调用该方法可以发送通知 * @param notifyId notifyId * @param title title * @param content content */ public void sendNotificationCompat(int notifyId, String title, String content , int icon) { NotificationCompat.Builder builder = getNotificationCompat(title, content, icon); Notification build = builder.build(); if (flags!=null && flags.length>0){ for (int a=0 ; a<flags.length ; a++){ build.flags |= flags[a]; } } getManager().notify(notifyId, build); }
Example #28
Source File: InputManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void showMissingKeyboardLayoutNotification(InputDevice device) { if (!mKeyboardLayoutNotificationShown) { final Intent intent = new Intent(Settings.ACTION_HARD_KEYBOARD_SETTINGS); if (device != null) { intent.putExtra(Settings.EXTRA_INPUT_DEVICE_IDENTIFIER, device.getIdentifier()); } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); final PendingIntent keyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT); Resources r = mContext.getResources(); Notification notification = new Notification.Builder(mContext, SystemNotificationChannels.PHYSICAL_KEYBOARD) .setContentTitle(r.getString( R.string.select_keyboard_layout_notification_title)) .setContentText(r.getString( R.string.select_keyboard_layout_notification_message)) .setContentIntent(keyboardLayoutIntent) .setSmallIcon(R.drawable.ic_settings_language) .setColor(mContext.getColor( com.android.internal.R.color.system_notification_accent_color)) .build(); mNotificationManager.notifyAsUser(null, SystemMessage.NOTE_SELECT_KEYBOARD_LAYOUT, notification, UserHandle.ALL); mKeyboardLayoutNotificationShown = true; } }
Example #29
Source File: NotificationParser.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
private void getExtraData(Notification notification) { RemoteViews views = notification.contentView; if (views == null) return; parseRemoteView(views); }
Example #30
Source File: RLPushHelper.java From Roid-Library with Apache License 2.0 | 5 votes |
/** * @param isDebug */ public void init(boolean isDebug) { JPushInterface.setDebugMode(isDebug); JPushInterface.init(mContext); JPushInterface.setLatestNotifactionNumber(mContext, LASTEST_NOTIFICATION_NUMBER); BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(mContext); builder.notificationFlags = Notification.FLAG_AUTO_CANCEL; builder.notificationDefaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; builder.developerArg0 = "data"; JPushInterface.setPushNotificationBuilder(1, builder); }