Android 进入设置画面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/623225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Go to settings screen
提问by lostInTransit
I want to open the Settings-> Sound & Display-> Phone Ringtones screen from my application. How can I do that?
我想从我的应用程序中打开设置-> 声音和显示-> 电话铃声屏幕。我怎样才能做到这一点?
回答by Reto Meier
Depending on your needs, there are a couple of alternatives to bring up the 'Ringtones' settings screen from your application.
根据您的需要,有几种替代方法可以从您的应用程序中调出“铃声”设置屏幕。
If you want to bring up the actual preferences screen that is usually available through system settings -- letting your user modify the phone's universal ringtone settings through your application -- you can use the ACTION_SOUND_SETTINGS
constant from the android.provider.Settings
class to create a new Intent to start the sound settings activity.
如果您想调出通常通过系统设置可用的实际首选项屏幕——让您的用户通过您的应用程序修改手机的通用铃声设置——您可以使用类中的ACTION_SOUND_SETTINGS
常量 android.provider.Settings
来创建一个新的 Intent 来启动声音设置活动。
startActivityForResult(new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS), 0);
If you want to select a custom ringtone to use in your application you need to add a RingtonePreference
in your preferences.xml
definition file, like this:
如果要选择在应用程序中使用的自定义铃声,则需要RingtonePreference
在preferences.xml
定义文件中添加一个,如下所示:
<RingtonePreference
android:key="alerts_ringtone"
android:title="Select ringtone"
android:showDefault="true"
android:showSilent="true"
android:ringtoneType=""
/>
You'll be able to get the URI to the selected preference in the application's default SharedPreferences
using alerts_ringtone
as the key.
您将能够SharedPreferences
使用alerts_ringtone
作为键的应用程序默认设置中所选首选项的 URI 。
The latter technique uses the PreferenceActivity
class to host the preference options. I won't describe that in detail here, as the Android documentation has a good writeupand some sample code.
后一种技术使用PreferenceActivity
类来承载首选项选项。我不会在这里详细描述,因为 Android 文档有很好的文章和一些示例代码。
回答by RED.Skull
This is an alternate solution for the problem. I am also working in the same task but the above code does not work for me. I have changed the code to
这是该问题的替代解决方案。我也在做同样的任务,但上面的代码对我不起作用。我已将代码更改为
startActivityForResult(new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS), 0);
and it now works.
它现在可以工作了。