我想通過我的android應用程序設置鈴聲。我試着用這個代碼如何通過Android應用程序設置鈴聲?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String filepath ="/sdcard/sound.mp3";
File ringtoneFile = new File(filepath);
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
System.out.println(ringtoneFile.getAbsolutePath()+"+++++++++++++++++++++++++");
content.put(MediaStore.MediaColumns.TITLE, "chinnu");
content.put(MediaStore.MediaColumns.SIZE, 215454);
content.put(MediaStore.MediaColumns.MIME_TYPE, "sound.mp3");
content.put(MediaStore.Audio.Media.ARTIST, "Madonna");
content.put(MediaStore.Audio.Media.DURATION, 230);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
content.put(MediaStore.Audio.Media.IS_ALARM, false);
content.put(MediaStore.Audio.Media.IS_MUSIC, false);
//Insert it into the database
String TAG="";
Log.i(TAG, "the absolute path of the file is :"+
ringtoneFile.getAbsolutePath());
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
ringtoneFile.getAbsolutePath());
Uri newUri = Context.getContentResolver().insert(uri, content);
ringtoneUri = newUri;
Log.i(TAG,"the ringtone uri is :"+ringtoneUri);
RingtoneManager.setActualDefaultRingtoneUri(context,
RingtoneManager.TYPE_RINGTONE,newUri);
}
}
但我得到的錯誤:context
不能被解析爲一個類型。這是什麼意思?我是一名android開發的初學者。我也設置了write_ external_storage permission
。
我還需要做些什麼才能成功運行此應用程序?
在此先感謝
@milind ...謝謝....現在showins中的錯誤,這些3 lines..ringtoneUri = newUri; Log.i(TAG,「the ringtone uri is:」+ ringtoneUri); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE,newUri); ...... ringtoneuri未解析爲類型....然後在RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE,newUri);. in這個代碼我們正在使用上下文......如何避免這種情況.....? – Sarath 2011-04-11 09:16:44