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

本文介绍了一位开发者尝试在Android应用中通过状态栏通知播放res/raw目录下的MP3文件的过程,使用了NotificationManager和Notification,但未提及为何声音未播放,寻求解决方案。
摘要由CSDN通过智能技术生成

我试图在状态栏通知中进行自定义声音播放. .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, 0, 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);

}

谢谢.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值