大佬教程收集整理的这篇文章主要介绍了自定义通知声音,android奥利奥?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
private void sendMyNotification(String messagE) { Intent intent; if (sharedPreferences.getBoolean(SPConstants.IS_LOGGED_IN,falsE)) { intent = new Intent(this,ActivityNotification.class); } else { intent = new Intent(this,ActivitySplash.class); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOp); PendingIntent pendingIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_ONE_SHOT); Uri soundUri = @L_475_4@manager.getDefaultUri(@L_475_4@manager.TYPE_NOTIFICATION); soundUri = Uri.parse("android.resource://" + getApplicationContext().getPackagename() + "/" + R.raw.panic); Au@L_121_6@manager manager = (Au@L_121_6@manager)getSystemservice(Context.AUdio_serviCE); manager.setStreamVolume(Au@L_121_6@manager.STREAM_MUSIC,100,0); NotificationCompat.builder notificationBuilder = new NotificationCompat.builder(this,CHAnnEL_ID) .setsmallIcon(R.mipmap.ic_launcher) .setContenttitle(getString(R.String.app_Name)) .setContentText(messagE) .setAutoCancel(true) .setSound(soundUri) .setContenTintent(pendingIntent); notificationmanager notificationmanager = (notificationmanager) getSystemservice(Context.NOTIFICATION_serviCE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODEs.O) { NotificationChAnnel mChAnnel = new NotificationChAnnel(CHAnnEL_ID,chAnnelName,notificationmanager.IMPORTANCE_HIGH); notificationmanager.createNotificationChAnnel(mChAnnel); } notificationmanager.notify(0,notificationBuilder.build()); }
恐慌音频文件位于res-> raw.
我试图使用声音的mp3和wav格式,但似乎没有什么工作来设置通知声音.
我目前正在测试Pixel 2 OS 8.1.
有什么建议可能是什么问题?
private void sendMyNotification(String messagE) { Intent intent = new Intent(this,SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOp); PendingIntent pendingIntent = PendingIntent.getActivity(this,PendingIntent.FLAG_ONE_SHOT); Uri soundUri = Uri.parse("android.resource://" + getApplicationContext().getPackagename() + "/" + R.raw.correct_answer); NotificationCompat.builder notificationBuilder = new NotificationCompat.builder(this,"CH_ID") .setsmallIcon(R.mipmap.ic_launcher) .setContenttitle(getString(R.String.app_Name)) .setContentText(messagE) .setAutoCancel(true) .setSound(soundUri) .setContenTintent(pendingIntent); notificationmanager mnotificationmanager = (notificationmanager) getSystemservice(Context.NOTIFICATION_serviCE); if (android.os.build.VERSION.SDK_INT >= android.os.build.VERSION_CODEs.O) { if(soundUri != null){ // Changing Default mode of notification notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE); // CreaTing an Audio Attribute AudioAttributes audioAttributes = new AudioAttributes.builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributeS.USAGE_ALARM) .build(); // CreaTing ChAnnel NotificationChAnnel notificationChAnnel = new NotificationChAnnel("CH_ID","TesTing_Audio",notificationmanager.IMPORTANCE_HIGH); notificationChAnnel.setSound(soundUri,audioAttributes); mnotificationmanager.createNotificationChAnnel(notificationChAnnel); } } mnotificationmanager.notify(0,notificationBuilder.build()); }
更新
以上是大佬教程为你收集整理的自定义通知声音,android奥利奥?全部内容,希望文章能够帮你解决自定义通知声音,android奥利奥?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。