保存铃声并再次获取

时间:2016-06-15 13:59:33

标签: android android-sharedpreferences

我正在开发一个应用程序,在该应用程序中,我获取当前的铃声并将其保存在sharedprefrences中并再次获取。我试着这样,但它不起作用。请告诉我错误在哪里?我是android的新手。请告诉我代码。

Uri currentRintoneUri = RingtoneManager.getActualDefaultRingtoneUri(context
                                    .getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
Ringtone currentRingtone = RingtoneManager.getRingtone(context, currentRintoneUri);
String stringUri;
stringUri = currentRingtone.toString();

sharedpreferences = getSharedPreferences(MyPRE, Context.MODE_PRIVATE);
String current = sharedpreferences.getString(CUR, "");
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(CUR, stringUri);
editor.commit();
t1.setText("Current Ringtone : " + currentRingtone.getTitle(context));

Ringtone currentRing = RingtoneManager.getRingtone(context, Uri.parse(current));
//  uri = Uri.parse(current);
currentRing.play();

0 个答案:

没有答案