大家好,我想以编程方式设置设备铃声,但应用程序崩溃。
我使用的代码是这样的:
@Override
public void onClick(View v) {
Uri uri = Uri.parse("android.resource://"
+"com.ghzncl.barneystinsonsoundboard/"+R.raw.single]);
RingtoneManager.setActualDefaultRingtoneUri(
mContext, RingtoneManager.TYPE_NOTIFICATION, uri
);
// I set the data source of the mPlayer. I pass to
// the method the context and the uri of the resource.
try{
// I reset the mPlayer to its uninitialized state, in
// this way I don't need to stop the previews running quotes.
mPlayer.reset();
mPlayer.setDataSource(mContext,uri);
}catch(Exception e){
// Do Exception handling here...
}
try{
mPlayer.prepare();
}catch(Exception e){
// Do Exception handling here...
}
//The quotes start
mPlayer.start();
}
任何人都可以帮助我吗?