我正试图创建一个墙纸应用程序,在该应用程序中提供了墙纸和铃声……我在该应用程序中创建了一个活动,在其中显示了所有铃声并有一个下载按钮,单击该按钮后,音频文件已下载到下载文件夹中,然后会显示一个弹出窗口,询问用户要将音频文件添加为铃声,警报或通知音,我希望在用户单击任一按钮,然后音频应将系统音频文件替换为下载的音频文件...我已尽力而为,但是没有用。仍然是默认的警报音...所以请帮助我,以便我可以使用户从系统上更改声音为已下载文件...
下面是我在我的应用程序中使用的代码,用于将文件设置为警报,铃声或单击按钮后执行的通知铃声。
setasalarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(mcontext,"check",Toast.LENGTH_LONG).show();
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/Download/"+filenamedata);
File file =new File(String.valueOf(uri));
if(file.exists()){
try {
if (checkSystemWritePermission()) {
RingtoneManager.setActualDefaultRingtoneUri(mcontext, RingtoneManager.TYPE_ALARM, uri);
Toast.makeText(mcontext, "Set as alarm successfully ", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(mcontext, "Allow modify system settings ==> ON ", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.i("alarm",e.toString());
Toast.makeText(mcontext, "unable to set as alarm ", Toast.LENGTH_SHORT).show();
}
alertDialog.dismiss();
}else{
Toast.makeText(mcontext,"not availabe",Toast.LENGTH_LONG).show();
alertDialog.dismiss();
}
}
});
setasringtone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(mcontext,"check",Toast.LENGTH_LONG).show();
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/Download/"+filenamedata);
File file =new File(String.valueOf(uri));
if(file.exists()){
try {
if (checkSystemWritePermission()) {
RingtoneManager.setActualDefaultRingtoneUri(mcontext, RingtoneManager.TYPE_RINGTONE, uri);
Toast.makeText(mcontext, "Set as Ringtone successfully ", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(mcontext, "Allow modify system settings ==> ON ", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.i("alarm",e.toString());
Toast.makeText(mcontext, "unable to set as ringtone ", Toast.LENGTH_SHORT).show();
}
alertDialog.dismiss();
}else{
Toast.makeText(mcontext,"not availabe",Toast.LENGTH_LONG).show();
alertDialog.dismiss();
}
}
});
setasnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(mcontext,"check",Toast.LENGTH_LONG).show();
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/Download/"+filenamedata);
File file =new File(String.valueOf(uri));
if(file.exists()){
try {
if (checkSystemWritePermission()) {
RingtoneManager.setActualDefaultRingtoneUri(mcontext, RingtoneManager.TYPE_NOTIFICATION, uri);
Toast.makeText(mcontext, "Set as Notification successfully ", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(mcontext, "Allow modify system settings ==> ON ", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.i("alarm",e.toString());
Toast.makeText(mcontext, "unable to set as notification ", Toast.LENGTH_SHORT).show();
}
alertDialog.dismiss();
}else{
Toast.makeText(mcontext,"not availabe",Toast.LENGTH_LONG).show();
alertDialog.dismiss();
}
}
});