Java Code Examples for android.app.NotificationChannel#setSound()
The following examples show how to use
android.app.NotificationChannel#setSound() .
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: NotificationChannels.java From mollyim-android with GNU General Public License v3.0 | 7 votes |
@TargetApi(26) private static @NonNull NotificationChannel copyChannel(@NonNull NotificationChannel original, @NonNull String id) { NotificationChannel copy = new NotificationChannel(id, original.getName(), original.getImportance()); copy.setGroup(original.getGroup()); copy.setSound(original.getSound(), original.getAudioAttributes()); copy.setBypassDnd(original.canBypassDnd()); copy.enableVibration(original.shouldVibrate()); copy.setVibrationPattern(original.getVibrationPattern()); copy.setLockscreenVisibility(original.getLockscreenVisibility()); copy.setShowBadge(original.canShowBadge()); copy.setLightColor(original.getLightColor()); copy.enableLights(original.shouldShowLights()); return copy; }
Example 2
Source File: MyActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
private void listing11_22(NotificationChannel channel, NotificationCompat.Builder builder) { // Listing 11-22: Customizing a Notification's alerts // For Android 8.0+ higher devices: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), null); channel.setVibrationPattern(new long[]{1000, 1000, 1000, 1000, 1000}); channel.setLightColor(Color.RED); } else { // For Android 7.1 or lower devices: builder.setPriority(NotificationCompat.PRIORITY_HIGH) .setSound( RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}) .setLights(Color.RED, 0, 1); } }
Example 3
Source File: SmbService.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //创建NotificationChannel if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ NotificationChannel channel = new NotificationChannel("com.xyoye.dandanplay.smbservice.playchannel", "SMB服务", NotificationManager.IMPORTANCE_LOW); channel.enableVibration(false); channel.setVibrationPattern(new long[]{0}); channel.enableLights(false); channel.setSound(null, null); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); } } startForeground(NOTIFICATION_ID, buildNotification()); return super.onStartCommand(intent, flags, startId); }
Example 4
Source File: ApplyOnBootService.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setSound(null, null); notificationManager.createNotificationChannel(notificationChannel); Notification.Builder builder = new Notification.Builder( this, CHANNEL_ID); builder.setContentTitle(getString(R.string.apply_on_boot)) .setSmallIcon(R.mipmap.ic_launcher); startForeground(NotificationId.APPLY_ON_BOOT, builder.build()); } }
Example 5
Source File: ApplicationEx.java From tracker-control-android with GNU General Public License v3.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.O) private void createNotificationChannels() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel foreground = new NotificationChannel("foreground", getString(R.string.channel_foreground), NotificationManager.IMPORTANCE_MIN); foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); nm.createNotificationChannel(foreground); NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT); notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); nm.createNotificationChannel(notify); NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT); access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); nm.createNotificationChannel(access); }
Example 6
Source File: MediaNotificationManager.java From flutter_exoplayer with MIT License | 6 votes |
private NotificationManager initNotificationManager() { NotificationManager notificationManager; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "Playback", android.app.NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setSound(null, null); notificationChannel.setShowBadge(false); notificationManager = (android.app.NotificationManager) this.context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); } else { notificationManager = (android.app.NotificationManager) this.context .getSystemService(Context.NOTIFICATION_SERVICE); } return notificationManager; }
Example 7
Source File: NotificationHelper.java From adamant-android with GNU General Public License v3.0 | 6 votes |
@RequiresApi(Build.VERSION_CODES.O) public static String createSilentNotificationChannel(String channelId, String channelName, Context context){ NotificationChannel chan = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_NONE); chan.setDescription("Silent channel"); chan.setSound(null,null); chan.enableLights(false); chan.setLightColor(Color.BLUE); chan.enableVibration(false); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); NotificationManager service = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (service != null) { service.createNotificationChannel(chan); } return channelId; }
Example 8
Source File: NotificationUtils.java From YCUpdateApp with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.O) private void createNotificationChannel() { //第一个参数:channel_id //第二个参数:channel_name //第三个参数:设置通知重要性级别 //注意:该级别必须要在 NotificationChannel 的构造函数中指定,总共要五个级别; //范围是从 NotificationManager.IMPORTANCE_NONE(0) ~ NotificationManager.IMPORTANCE_HIGH(4) NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); channel.canBypassDnd();//是否绕过请勿打扰模式 channel.enableLights(true);//是否在桌面icon右上角展示小红点 channel.setLockscreenVisibility(VISIBILITY_SECRET);//锁屏显示通知 channel.setLightColor(Color.RED);//闪关灯的灯光颜色 channel.canShowBadge();//桌面launcher的消息角标 //channel.enableVibration(false);//是否允许震动 channel.getAudioAttributes();//获取系统通知响铃声音的配置 channel.getGroup();//获取通知取到组 channel.setBypassDnd(true);//设置可绕过 请勿打扰模式 channel.setSound(null, null); //channel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式 channel.shouldShowLights();//是否会有灯光 channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知 getManager().createNotificationChannel(channel); }
Example 9
Source File: SoundService.java From volume_control_android with MIT License | 5 votes |
private void createStaticNotificationChannel() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(staticNotificationId, "Static notification widget", NotificationManager.IMPORTANCE_DEFAULT); channel.setSound(null, null); channel.enableVibration(false); notificationManagerCompat.createNotificationChannel(channel); } }
Example 10
Source File: KcaService.java From kcanotify_h5-master with GNU General Public License v3.0 | 5 votes |
private void createServiceChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int priority = IMPORTANCE_DEFAULT; if (getBooleanPreferences(getApplicationContext(), PREF_KCA_SET_PRIORITY)) { priority = IMPORTANCE_HIGH; } NotificationChannel channel = new NotificationChannel(getServiceChannelId(), SERVICE_CHANNEL_NAME, priority); channel.enableVibration(false); channel.setSound(null, null); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); notifiManager.deleteNotificationChannel(SERVICE_CHANNEL_ID_OLD); notifiManager.createNotificationChannel(channel); } }
Example 11
Source File: SubscriptionsFeedFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private void showNotification() { // Sets an ID for the notification, so it can be updated. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); mChannel.setSound(null,null); // Create a notification and set the notification channel. Notification notification = new Notification.Builder(getContext(), NOTIFICATION_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_notification_icon) .setContentTitle(getString(R.string.fetching_subscription_videos)) .setContentText(String.format(getContext().getString(R.string.fetched_videos_from_channels), numVideosFetched, numChannelsFetched, numChannelsSubscribed)) .setChannelId(NOTIFICATION_CHANNEL_ID) .build(); mNotificationManager.createNotificationChannel(mChannel); // Issue the notification. mNotificationManager.notify(NOTIFICATION_ID , notification); } else { final Intent emptyIntent = new Intent(); PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 1, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext(), "") .setSmallIcon(R.drawable.ic_notification_icon) .setContentTitle(getString(R.string.fetching_subscription_videos)) .setContentText(String.format(getContext().getString(R.string.fetched_videos_from_channels), numVideosFetched, numChannelsFetched, numChannelsSubscribed)) .setPriority(NotificationCompat.FLAG_ONGOING_EVENT) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); } }
Example 12
Source File: NotificationHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
public static void createDownloadChannel(Context c, @NonNull NotificationManager manager) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( CHANNEL_ID_DOWNLOAD, getNotificationChannelName(c, CHANNEL_ID_DOWNLOAD), NotificationManager.IMPORTANCE_LOW); channel.setShowBadge(true); channel.setSound(null, null); channel.setLightColor(ContextCompat.getColor(c, R.color.colorNotification)); manager.createNotificationChannel(channel); } }
Example 13
Source File: NotifyManager.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
private void createNotifyChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (mNotificationManager != null) { mNotificationManager.createNotificationChannelGroup( new NotificationChannelGroup(mGroupId, mGroupName)); NotificationChannel channelMsg = new NotificationChannel(mChannelMsgId, mChannelMsgName, NotificationManager.IMPORTANCE_DEFAULT); channelMsg.setDescription(mChannelMsgDes); channelMsg.enableLights(true); channelMsg.setLightColor(Color.BLUE); channelMsg.enableVibration(false); channelMsg.setVibrationPattern(new long[] { 100, 200, 300, 400 }); channelMsg.setShowBadge(true); channelMsg.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); channelMsg.setGroup(mGroupId); mNotificationManager.createNotificationChannel(channelMsg); NotificationChannel channelService = new NotificationChannel(mChannelServiceId, mChannelServiceName, NotificationManager.IMPORTANCE_LOW); channelService.setDescription(mChannelServiceDes); channelService.enableLights(false); channelService.enableVibration(false); channelService.setShowBadge(false); channelService.setSound(null, null); channelService.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); channelService.setGroup(mGroupId); mNotificationManager.createNotificationChannel(channelService); } } }
Example 14
Source File: NotificationChannels.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.O) private synchronized void createAppNotificationChannel() throws ApplozicException { CharSequence name = MobiComKitConstants.APP_NOTIFICATION_NAME; int importance = NotificationManager.IMPORTANCE_HIGH; if (mNotificationManager != null && mNotificationManager.getNotificationChannel(MobiComKitConstants.AL_APP_NOTIFICATION) == null) { NotificationChannel mChannel = new NotificationChannel(MobiComKitConstants.AL_APP_NOTIFICATION, name, importance); mChannel.enableLights(true); mChannel.setLightColor(Color.GREEN); mChannel.setShowBadge(ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()); if (ApplozicClient.getInstance(context).getVibrationOnNotification()) { mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); } AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION).build(); if (TextUtils.isEmpty(soundFilePath)) { throw new ApplozicException("Custom sound path is required to create App notification channel. " + "Please set a sound path using Applozic.getInstance(context).setCustomNotificationSound(your-sound-file-path)"); } mChannel.setSound(Uri.parse(soundFilePath), audioAttributes); mNotificationManager.createNotificationChannel(mChannel); Utils.printLog(context, TAG, "Created app notification channel"); } }
Example 15
Source File: Manager.java From cordova-plugin-firebase-extended-notification with MIT License | 5 votes |
private void createNotificationChannel(Options options) { // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_DEFAULT; if(options.doesHeadsUp()) { importance = NotificationManager.IMPORTANCE_HIGH; } else if(!options.doesSound()) { importance = NotificationManager.IMPORTANCE_LOW; } NotificationChannel channel = new NotificationChannel(options.getChannelId(), options.getChannelName(), importance); if(options.doesHeadsUp()) { channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); } channel.setDescription(options.getChannelDescription()); if(options.doesSound() && options.getSoundUri() != null) { AudioAttributes audioAttributes = new AudioAttributes.Builder() .setLegacyStreamType(android.media.AudioManager.STREAM_NOTIFICATION) .build(); channel.setSound(options.getSoundUri(), audioAttributes); } // Register the channel with the system; you can't change the importance // or other notification behaviors after this NotificationManager notificationManager = this.context.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } }
Example 16
Source File: MapTrek.java From trekarta with GNU General Public License v3.0 | 5 votes |
@TargetApi(26) private void createNotificationChannel() { NotificationChannel channel = new NotificationChannel("ongoing", getString(R.string.notificationChannelName), NotificationManager.IMPORTANCE_LOW); channel.setShowBadge(false); channel.setSound(null, null); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (notificationManager != null) notificationManager.createNotificationChannel(channel); }
Example 17
Source File: ScreenshotDecorator.java From EnhancedScreenshotNotification with GNU General Public License v3.0 | 5 votes |
@RequiresApi(Build.VERSION_CODES.O) private void ensureEvolvedNotificationChannel() { final NotificationChannel screenshotChannel = new NotificationChannel( CHANNEL_ID_SCREENSHOT, getString(R.string.noti_channel_screenshot), NotificationManager.IMPORTANCE_HIGH ); screenshotChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build()); screenshotChannel.enableLights(false); final NotificationChannel otherChannel = new NotificationChannel( CHANNEL_ID_OTHER, getString(R.string.noti_channel_other), NotificationManager.IMPORTANCE_DEFAULT ); screenshotChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build()); screenshotChannel.enableLights(true); final NotificationChannel previewedChannel = new NotificationChannel( CHANNEL_ID_PREVIEWED_SCREENSHOT, getString(R.string.noti_channel_screenshot_preview), NotificationManager.IMPORTANCE_MIN ); previewedChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build()); previewedChannel.enableLights(false); createNotificationChannels( TARGET_PACKAGE, Arrays.asList(screenshotChannel, otherChannel, previewedChannel)); }
Example 18
Source File: TorrentService.java From DanDanPlayForAndroid with MIT License | 5 votes |
/** * 初始化数据 */ private void initData() { //初始化广播 wifiReceiver = new WifiReceiver(isConnected -> { if (TorrentConfig.getInstance().isDownloadOnlyWifi() && !isConnected) { ToastUtils.showShort("wifi连接断开,已暂停所有下载任务"); TorrentEngine.getInstance().pauseAll(); } }); registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); //初始化刷新 syncNotifyHandler = new Handler(); syncNotifyRunnable = new Runnable() { @Override public void run() { isRefreshing.set(true); updateUIData(); startForeground(NOTIFICATION_ID, buildNotification()); syncNotifyHandler.postDelayed(this, NOTIFY_SYNC_TIME); } }; //初始化通知 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel("com.xyoye.dandanplay.TorrentService.DownloadChannel", "TorrentService", NotificationManager.IMPORTANCE_LOW); channel.enableVibration(false); channel.setVibrationPattern(new long[]{0}); channel.enableLights(false); channel.setSound(null, null); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); } } startForeground(NOTIFICATION_ID, buildNotification()); }
Example 19
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(Notification.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(temp.vibrate); template.setSound(temp.sound, generic_audio); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }
Example 20
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(NotificationCompat.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(wip.mNotification.vibrate); template.setSound(wip.mNotification.sound, generic_audio); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }