问题描述
我正在制作铃声应用程序,并希望将原始文件夹声音设置为铃声。铃声已成功设置并首先保存在Android手机上的外部文件夹中,但是当我再次将该声音设置为铃声时,铃声将变为静音。
public boolean saveas() {
byte[] buffer = null;
InputStream fIn = getBaseContext().getResources().openRawResource(
R.raw.ertugrul_music);
int size = 0;
try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
}
catch (IOException e) {
return false;
}
boolean exists = (new File(path,filename)).exists();
if (!exists)
{
new File(path).mkdirs();
}
FileOutputStream save;
try {
save = new FileOutputStream(path + filename);
save.write(buffer);
save.flush();
save.close();
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
return false;
}
k = new File(path,filename);
ContentValues values = new ContentValues();
long current = System.currentTimeMillis();
values.put(MediaStore.MediaColumns.DATA,path + filename);
values.put(MediaStore.MediaColumns.TITLE,filename);
values.put(MediaStore.Audio.Media.DATE_ADDED,(int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE,"audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST,"cssounds ");
values.put(MediaStore.Audio.Media.IS_ringtone,true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION,true);
values.put(MediaStore.Audio.Media.IS_ALARM,true);
values.put(MediaStore.Audio.Media.IS_MUSIC,true);
try {
Uri newUri = this.getContentResolver()
.insert(MediaStore.Audio.Media.getContentUriForPath(k
.getAbsolutePath()),values);
ringtoneManager.setActualDefaultringtoneUri(MainActivity.this,ringtoneManager.TYPE_ringtone,newUri);
Toast.makeText(this,new StringBuilder().append("ringtone set successfully"),Toast.LENGTH_LONG).show();
} catch (Throwable th) {
Toast.makeText(this,new StringBuilder().append("ringtone feature is not
working"),Toast.LENGTH_LONG).show();
}
return true;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)