如何在 Android 上调出可用通知声音列表 [英] How to bring up list of available notification sounds on Android

查看:29
本文介绍了如何在 Android 上调出可用通知声音列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 Android 应用程序中创建通知,并希望在我的首选项中有一个选项来设置用于通知的声音.我知道在设置"应用程序中,您可以从列表中选择默认通知声音.该列表来自哪里,有没有办法在我的应用程序中显示相同的列表?

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?

推荐答案

只需从我的一款应用中复制/粘贴一些代码,即可完成您的需求.

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);

此代码捕获用户所做的选择:

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;
        }
    }            
}

另外,我建议我的用户安装Rings Extended"来自 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.

这篇关于如何在 Android 上调出可用通知声音列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆