如何使用RingtoneManager.ACTION_RINGTONE_PICKER设置铃声?

发布于 2024-12-08 08:18:39 字数 1139 浏览 1 评论 0原文

我尝试在这里找到解决方案,但只有自己/所选文件的解决方案,而当我调用选择器时没有代码的解决方案。当用户按下按钮时,我使用以下代码:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
ActivityCurrent.this.startActivityForResult(intent,999);

这显示铃声选择器,用户可以选择想要的铃声,但我错过了两件事: - 打开时不显示当前铃声 - 单击“确定”时不会保存铃声


我仍然找不到如何使用已选择的当前铃声打开 RINGTONE_PICKER 的方法。有什么想法吗?

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
ActivityCurrent.this.startActivityForResult(intent,999);

I try to find solution here, but there are only solution for own/selected file, not for code when I call picker. I use following code when user press button:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
ActivityCurrent.this.startActivityForResult(intent,999);

This show ringtone picker, user can choose what ringtone wants, but I miss two things:
- it doesn´t show current ringtone when it open
- it not save ringtone when it is clicked on OK


I still can´t find way how to open RINGTONE_PICKER with already selected current ring tone. Any idea?

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
ActivityCurrent.this.startActivityForResult(intent,999);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我不是你的备胎 2024-12-15 08:18:39

您必须实现 onActivityResult() 来接收用户选择的结果,然后保存它。

if (resultCode == RESULT_OK) {
    Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    if (uri != null) {
    String ringTonePath = uri.toString();
}

这里有一个例子: http://www.ceveni .com/2009/07/ringtone-picker-in-android-with-intent.html

编辑:更新

RingtoneManager.setActualDefaultRingtoneUri(
    myActivity,
    RingtoneManager.TYPE_RINGTONE,
    uri);

您必须调用此:)

You must implement onActivityResult() to receive result from user's pick, then save it.

if (resultCode == RESULT_OK) {
    Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    if (uri != null) {
    String ringTonePath = uri.toString();
}

Here an example: http://www.ceveni.com/2009/07/ringtone-picker-in-android-with-intent.html

EDIT: update

RingtoneManager.setActualDefaultRingtoneUri(
    myActivity,
    RingtoneManager.TYPE_RINGTONE,
    uri);

You must call this :)

傾旎 2024-12-15 08:18:39
Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtone);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, ringtone);
startActivityForResult(intent , 1);

“ringtone”是我在 onActivityResult() 中保存所选铃声的 uri。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case 1:
            ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            // Toast.makeText(getBaseContext(),RingtoneManager.URI_COLUMN_INDEX,
            // Toast.LENGTH_SHORT).show();
            break;

        default:
            break;
        }
    }
}

希望对您有帮助。如果确实如此,请点击回答。

Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtone);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, ringtone);
startActivityForResult(intent , 1);

"ringtone" is the uri in which I am saving the picked tone in onActivityResult().

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case 1:
            ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            // Toast.makeText(getBaseContext(),RingtoneManager.URI_COLUMN_INDEX,
            // Toast.LENGTH_SHORT).show();
            break;

        default:
            break;
        }
    }
}

Hope it helps you. Hit answered if it does.

む无字情书 2024-12-15 08:18:39

该代码非常完美并且适合我。但你忘了提及所需的权限..就在这里。尝试这个代码..希望它有帮助

<uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
  <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" ></uses-permission>
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" ></uses-permission>

The code is perfect and works for me. But you forgot to mention the permissions required..here it is. try this code..hope it helps

<uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
  <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" ></uses-permission>
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" ></uses-permission>
沩ん囻菔务 2024-12-15 08:18:39

此代码将显示用户在使用铃声选择器时之前设置的默认铃声。

在按钮中使用以下代码来获取铃声意图。

public void pickRingtone(View view) {
        // TODO Auto-generated method.   stub

        Intent intent = new.       Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                RingtoneManager.TYPE_RINGTONE);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Ringtone");

    // for existing ringtone
        Uri urie =     RingtoneManager.getActualDefaultRingtoneUri(
                getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, urie);

    startActivityForResult(intent, 5);
}

This code will show default ringtone which the user sets earlier when ringtone picker is used.

Use below code in the button for ringtone intent.

public void pickRingtone(View view) {
        // TODO Auto-generated method.   stub

        Intent intent = new.       Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                RingtoneManager.TYPE_RINGTONE);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Ringtone");

    // for existing ringtone
        Uri urie =     RingtoneManager.getActualDefaultRingtoneUri(
                getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, urie);

    startActivityForResult(intent, 5);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文