android – 自定义通知声音无法播放

我试图在状态栏通知中进行自定义声音播放. .mp3文件在res / raw /中.但是当我通知用户声音没有播放.我已经试过MediaPlayer,它的作品,但我不想让它播放与MediaPlayer.

这是我的方法

public void showNotification()
{
        String ns = Context.NOTIFICATION_SERVICE;
        notificationmanager mnotificationmanager = (notificationmanager) getSystemService(ns);

        int icon = R.drawable.Feedback;        // icon from resources
        CharSequence tickerText = mContext.getString(R.string.statusbar_notification); // ticker-text
        long when = System.currentTimeMillis();         // notification time
        Context context = getApplicationContext();      // application Context
        CharSequence contentTitle = mContext.getString(R.string.statusbar_notification);  // message title
        CharSequence contentText = mContext.getString(R.string.statusbar_notificatione_detailed);      // message text

        Intent notificationIntent = new Intent(mContext,Main.class);
        PendingIntent contentIntent = PendingIntent.getActivity(mContext,notificationIntent,0);

        // the next two lines initialize the Notification,using the configurations above
        Notification notification = new Notification(icon,tickerText,when);

        //notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.sound = Uri.parse("android.resource://" + getPackageName() + "/R.raw.notificationsound");

        notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent);
        mnotificationmanager.notify(1,notification);
}

谢谢.

解决方法

从ContentResolver的文档:

The Uri should be one of the following formats:
android.resource://package_name/id_number

你传递的字符串“R.raw.notificationsound”这意味着什么.
相反尝试这样:

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound );

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...