如何设置通知,在Android的自定义音效 [英] How to set notification with custom sound in android
本文介绍了如何设置通知,在Android的自定义音效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我复制的MP3(kalimba.mp3)文件到原始文件夹中的资源folder.But时通知上调了越来越默认sound.Is有任何错误,在code.Could请人帮我。
//上按一下按钮,我调用此方法///
保护无效GenerateNotify(){
NotificationManager myNotificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
通知通知=新的通知(android.R.drawable.ic_btn_speak_now,喜,100);
意向意图=新的意图(getApplicationContext(),as.class);
PendingIntent contentintent = PendingIntent.getBroadcast(getApplicationContext(),0,意图,0);
notification.setLatestEventInfo(getApplicationContext(),你好,日,contentintent);
notification.flags | = Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.parse(android.resource://com.example.serviceproject/+ R.raw.kalimba);
myNotificationManager.notify(NOTIFICATION_ID,通知);
}
解决方案
notification.sound = Uri.parse(android.resource://+ getPackageName()+/ + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
如果定义DEFAULT_SOUND,那么默认的声音覆盖的任何声音
I copied the mp3 (kalimba.mp3) file into raw folder in res folder.But when notification raised its getting default sound.Is there any error in the code.Could anyone please help me.
//on Button click i am calling this method///
protected void GenerateNotify() {
NotificationManager myNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(android.R.drawable.ic_btn_speak_now,"hi",100);
Intent intent=new Intent(getApplicationContext(),as.class);
PendingIntent contentintent=PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
notification.setLatestEventInfo(getApplicationContext(), "Hi","date", contentintent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.parse("android.resource://com.example.serviceproject/" + R.raw.kalimba);
myNotificationManager.notify(NOTIFICATION_ID,notification);
}
解决方案
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
if defined DEFAULT_SOUND, then the default sound overrides any sound
这篇关于如何设置通知,在Android的自定义音效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文