如何调出可用的通知名单声音在Android上声音、名单、通知、Android

2023-09-13 02:27:00 作者:可爱的白薯

我在我的Andr​​oid应用程序创建通知,并希望在我的preferences一个选项来设置什么声音用于通知。我知道,在设置应用程序,你可以从列表中选择一个默认的通知声音。来自哪里的列表,有没有办法对我来说,显示相同的列表中我的应用程序?

I'm creating notifications in my Android application, and would like to have an option in my preferences to set what sound is used for the notification. I know that in the Settings application you can choose a default notification sound from a list. Where does that list come from, and is there a way for me to display the same list in my application?

推荐答案

只要复制/粘贴一些code从我的应用程序之一,做你所期待的。

Just copy/pasting some code from one of my apps that does what you are looking for.

这是一个按钮的onclick处理标记设置铃声或类似的东西:

This is in an onClick handler of a button labeled "set ringtone" or something similar:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
this.startActivityForResult(intent, 5);

这code捕获用户作出的选择:

And this code captures the choice made by the user:

 @Override
 protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent)
 {
     if (resultCode == Activity.RESULT_OK && requestCode == 5)
     {
          Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

          if (uri != null)
          {
              this.chosenRingtone = uri.toString();
          }
          else
          {
              this.chosenRingtone = null;
          }
      }            
  }

另外,我建议我的用户从Android Market安装魔戒扩展应用程序。然后,每当打开他们的设备在此对话框,比如从我的应用程序,或从手机的设置菜单中,用户将不得不挑选任何存储在他们的设备,而不仅仅是内置铃声的MP3的附加选择。

Also, I advise my users to install the "Rings Extended" app from the Android Market. Then whenever this dialog is opened on their device, such as from my app or from the phone's settings menu, the user will have the additional choice of picking any of the mp3s stored on their device, not just the built in ringtones.