gpt4 book ai didi

android - 铃声在 android 2.3 上设置为静音,但在 4.0.3 上有效

转载 作者:行者123 更新时间:2023-11-29 02:05:48 24 4
gpt4 key购买 nike

我有两个问题:

  1. 当我在 android 4.0.3 设备上调用我的 saveas(ressound);(灵感来自 stealthcopter.com)时,铃声被很好地激活为铃声,但在 2.3. 3 设备选择的铃声是无声的。我的代码哪里出错了?

  2. 我想知道的第二件事是如何删除文件。更重要的是,如何将其从媒体存储中取出,如果我将其从 sd 中删除会自动发生吗?


更新:

添加了删除整个文件夹和内容的代码,效果很好,很干净! (见下文)

尝试在我按下按钮时调用此代码:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 

但它不会清除 mediastore,它需要重新启动才能工作。我还尝试了开发工具中的媒体扫描,但这不起作用。他们提到有些应用程序需要重启,但是如何在不重启整个设备的情况下重启负责显示可用铃声列表的服务?


变量:

String soundname;
int ressound;
int savetype;
String path="/sdcard/mysounds/";

savetype = RingtoneManager.TYPE_RINGTONE;
ressound = R.raw.sound1;
soundname = "sound1";

saveas(ressound);

//save as
public boolean saveas(int ressound){
byte[] buffer=null;
InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
int size=0;

try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
return false;
}

String filename= soundname +".mp3";

boolean exists = (new File(path)).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;
}

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));

File k = new File(path, filename);

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, soundname);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, "Elvis");
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, false);

//Insert it into the database
Uri newUri = this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

// set as ringtone
RingtoneManager.setActualDefaultRingtoneUri(this, savetype, newUri);

return true;
}

删除();

public void delete() {
File a = new File(path, "sound1.mp3");
a.delete();
File b = new File(path, "sound2.mp3");
b.delete();
}

deleteFiles(字符串路径);

public static void deleteFiles(String path) {
File file = new File(path);

if (file.exists()) {
String deleteCmd = "rm -r " + path;
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(deleteCmd);
} catch (IOException e) { }
}
}

最佳答案

“android.permission.MODIFY_AUDIO_SETTINGS”我认为这解决了问题一,直到现在没有发现任何问题。

删除文件(字符串路径);是问题2的部分解决方案重新启动后,项目消失了。

关于android - 铃声在 android 2.3 上设置为静音,但在 4.0.3 上有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10105877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com