【问题标题】:List all the available Notifications Ringtones in Android列出 Android 中所有可用的通知铃声
【发布时间】: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


    【解决方案1】:

    你可以将声音添加到你的原始文件夹,初始化它

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

    在需要的地方调用它

        mpSplash.start();
    

    【讨论】:

    • 我知道这一点,但我不想选择自定义声音,我想选择一种默认声音,比如进入 android 中的设置并更改通知声音。
    猜你喜欢
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多