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

}

谢谢.

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐