我设置了铃声,它可以正常工作但是" .MediaColumns.TITLE"和" .Media.ARTIST"不工作。我已设置铃声,然后检查。显示文件名而不是"标题名称"。
我的代码;
public boolean setRingtone(int p, String s) {
String path = Environment.getExternalStorageDirectory().getPath()
+ "/sdcard/media/audio/ringtones/";
String filename = s+'.mp3';
boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}
File k = new File(path, filename);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "Title Name");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, "Ringtones");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
getContentResolver().delete(uri,MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
Uri newUri = getContentResolver().insert(uri,values);
RingtoneManager.setActualDefaultRingtoneUri(SingleListItem.this,RingtoneManager.TYPE_RINGTONE,newUri);
String desc= "Ringtone has been set";
Toast.makeText(getApplicationContext(), desc, Toast.LENGTH_LONG).show();
return true;
}
我有这些权限
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
答案 0 :(得分:0)
你的插入看起来是正确的...我使用了几乎相同的代码,它的工作原理。它在哪里显示文件名而不是&#34;标题名称&#34;?在手机设置中或再次查询数据库中的媒体条目时?如果是在查询时,请确保索引到正确的列以获取字符串:
Uri ringtoneUri = ...however you are getting the URI...
String[] retCol = { MediaStore.MediaColumns.TITLE };
Cursor cur = context.getContentResolver().query(ringtoneUri,retCol,null,null, null);
if (cur.getCount() > 0) {
cur.moveToFirst();
String name = cur.getString(cur.getColumnIndex( MediaStore.MediaColumns.TITLE ));
//Do something with name...
}
cur.close();