【发布时间】:2012-08-28 20:31:04
【问题描述】:
我正在尝试更改通知的默认声音,我喜欢这样做:
private void showNotification(Context context, String reminderid, String title, String shortinfo, String longinfo)
{
mNM = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
NOTIFICATION=Integer.parseInt(reminderid);
Notification notification = new Notification(R.drawable.icon, title,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, RemindersActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
notification.setLatestEventInfo(context, shortinfo,
longinfo, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
notification.defaults |= Notification.DEFAULT_VIBRATE;
mNM.notify(NOTIFICATION, notification);
}
但是您可以注意到,我为URI.withAppendedPath() 提供了 ID“6”,我需要为用户列出所有可用的通知铃声并让他选择,我将传递他的 ID选择而不是“6”。
谷歌在这里说:
在这种情况下,媒体文件的确切 ID(“6”)是已知的并附加到内容 Uri。如果您不知道确切的 ID,则必须使用 ContentResolver 查询 MediaStore 中可用的所有媒体。有关使用 ContentResolver 的更多信息,请参阅 Content Providers 文档。
我怎样才能做到他们所说的(请注意,我从未与内容提供商或解析器合作过)?并为用户提供选择通知铃声的选项,就像在手机设置中选择它一样?
提前致谢。
【问题讨论】:
标签: java android audio notifications android-notifications