gpt4 book ai didi

android - 单击editText时如何选择音频文件?

转载 作者:行者123 更新时间:2023-12-03 00:08:28 24 4
gpt4 key购买 nike

单击片段类(ReminderPage)中的editText时,我希望它打开音频文件,以便可以选择音乐文件作为铃声。

ringtone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {

Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_GET_CONTENT);
intent1.setType("audio/*");
startActivityForResult(
Intent.createChooser(intent1, "Choose Sound File"), 6);
}
});

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data,Context context) {
if (resultCode == getActivity().RESULT_OK && requestCode == 6) {
Uri i = data.getData(); // getData
String s = i.getPath(); // getPath
File k = new File(s); // set File from path
if (s != null) { // file.exists

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "ring");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.MediaColumns.SIZE, k.length());
values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
.getAbsolutePath());
context.getContentResolver().delete(
uri,
MediaStore.MediaColumns.DATA + "=\""
+ k.getAbsolutePath() + "\"", null);
Toast.makeText(getActivity(),values+"",Toast.LENGTH_LONG).show();
Uri newUri = context.getContentResolver().insert(uri, values);

try {
RingtoneManager.setActualDefaultRingtoneUri(
getActivity().ReminderPage, RingtoneManager.TYPE_RINGTONE,
newUri);
} catch (Throwable t) {

}
}
}
}

但是我遇到了错误,并且从未使用过onActivityResult。

Error:(473, 42) error: cannot find symbol variable ReminderPage Error:(443, 5) error: method does not override or implement a method from a supertype



在我更改为getActivity()。getContentResolver()和Reminder.this之后,我得到了新的错误

Error:(444, 20) error: onActivityResult(int,int,Intent) in ReminderPage cannot override onActivityResult(int,int,Intent) in Fragment attempting to assign weaker access privileges; was public Error:(472, 36) error: method setActualDefaultRingtoneUri in class RingtoneManager cannot be applied to given types; required: Context,int,Uri found: ReminderPage,int,Uri reason: actual argument ReminderPage cannot be converted to Context by method invocation conversion

最佳答案

对于第一个错误,请在调用getActivity().ReminderPage时尝试用getActivity()替换setActualDefaultRingtoneUri

关于第二个错误:Fragment.onActivityResult方法中没有Context context参数,可见性应为public。覆盖方法时,必须尊重方法的签名。

更换

protected void onActivityResult(int requestCode, int resultCode, Intent data,Context context) {

通过
public void onActivityResult(int requestCode, int resultCode, Intent data) {

并更换
context.getContentResolver()

通过
getActivity().getContentResolver()

关于android - 单击editText时如何选择音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41042915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com