在 Android 中以编程方式设置铃声
大家好,我想以编程方式设置设备铃声,但应用程序崩溃了。
我使用的代码是这样的:
@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();
}
任何人都可以帮助我吗?
Hi guys I want to set the device ring-tone programmatically but the application crashes.
The code I used is this:
@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();
}
Anyone can please help me??
Nocola 我使用这段代码来设置为铃声:
但是我在这段代码中做了很多调整,不知何故我发现了 教程,介绍如何以编程方式制作闹钟铃声,并以您自己的方式...
做实验吧!
Nocola i used this code in order to set as ringtone:
But i did so much tweaking in this code, somehow i found the tutorial on how to make an alarm tone programmatically, and your own your way...
just do the experiment!