如何在Android中获取铃声名称? [英] How to get Ringtone name in Android?

查看:344
本文介绍了如何在Android中获取铃声名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许我的用户为我的应用中的通知选择铃声.我想将声音的URI和声音的可读标题存储在一起.

I'm allowing my user to pick a ringtone for notifications in my app. I want to store the URI of the sound along with the human readable title of the sound.

到目前为止,URI代码运行良好:

So far the URI code works great:

Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

但是当我尝试获取标题并将其设置为按钮文本时,我什么也没得到.似乎没有标题?

But when I try to get the title, and set it as a button text, I don't get anything. Seems to have no title?

String title = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
button.setText(title);

但是我的按钮文字为空.如果我这样做:

But my button text is empty. If I do:

button.setText(uri.toString());

然后我完美地看到了uri.我应该只是尝试从URI中获取标题吗?谢谢

then I see the uri perfectly. Should I just try to get the title from the URI? Thanks

推荐答案

这应该得到它:

Ringtone ringtone = RingtoneManager.getRingtone(this, uri);
String title = ringtone.getTitle(this);

请参阅 http://developer.android.com/reference/android/media/Ringtone.html 作为文档,但简短的故事是:Ringtone.getTitle(Context ctx);

Refer to http://developer.android.com/reference/android/media/Ringtone.html for the documentation, but the short story: Ringtone.getTitle(Context ctx);

这篇关于如何在Android中获取铃声名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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