问题描述
关于Stackoverflow至少有7个与此相关的问题,我已经多次尝试了每个建议和解决方案,但没有一个起作用.这是我最近的尝试:
There are at least 7 questions on Stackoverflow related to this, I have tried every single suggestion and solution multiple times and none of them have worked. Here is my latest attempt:
private Notification createNotification() {
Notification notification = new Notification();
if(notifyImage=="food")
{
notification.icon = R.drawable.food;
notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start");
}
else
{
notification.icon = R.drawable.bar;
notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start");
}
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
return notification;
}
您可以看到我尝试过两次都无法使用的声音,但是图标可以正常工作.我不知道是否缺少任何东西才能使它正常工作,但是我正在使用的所有代码都在我的帖子中.
You can see the two times I try and use a sound which never works, but the icons work perfectly. I do not know if I am missing anything in order to get this to work, but all of the code I am using is in my post.
我的声音文件在res/raw/start.mp3中,按一下按钮就可以使声音起作用,所以声音很好.
My sound file is in res/raw/start.mp3, I can get this sound to work when pressing a button, so the sound is fine.
我认为程序包名称正确,我的应用程序位于每个类的顶部:
I think the package name is right, my application at has this at the top of each class:
package com.example.memoryGuide;
有什么想法为什么声音永远不会播放?
Any ideas why the sound never plays?
推荐答案
使用
notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + getPackageName() + "/raw/start");
请注意一件事.
返回您的Android应用程序的包名称.还有
returns the package name of your android aplication. And
显示源软件包名称的软件包名称.
shows the package name of your source package name.
这篇关于URI解析发出的通知声音不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!