列出Android中所有可用的通知铃声

时间:2012-08-28 20:31:05

标签: java android audio notifications android-notifications

我正在尝试更改通知的默认声音,我确实喜欢这样:

     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”。

谷歌在这里说:

  

在这种情况下,媒体文件(“6”)的确切ID是已知的并附加到内容Uri。如果您不知道确切的ID,则必须使用ContentResolver查询MediaStore中的所有可用媒体。有关使用ContentResolver的详细信息,请参阅Content Providers文档。

我怎么做他们说的话(注意我从未与内容提供商或解析器合作过)?并为用户提供选择通知铃声的选项,例如在手机设置中选择?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以将声音添加到原始文件夹,进行初始化

MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.slow);

并在需要的地方拨打电话

    mpSplash.start();
相关问题