Мне помогли создать приложение несколько месяцев назад, и я пытаюсь создать его самостоятельно, и это не так просто, как хотелось бы.
Я хотел бы удалить файл, который имеетбыл создан в каталоге загрузки. Я использую эту папку в качестве папки кэша, чтобы поделиться звуком, хранящимся в моем приложении. Вот пример для опциона на акции (который хорошо работает, за исключением того, что я не понимаю, куда я должен поместить строку outputFile.delete();
...)
case R.id.partage:
File outputFile = new File("");
InputStream is = getResources().openRawResource(((Sound) adapter.getItem(index)).getMpsound());
try {
byte[] buffer = new byte[is.available()];
is.read(buffer);
File outputDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
outputFile = new File(outputDir, getResources().getResourceEntryName(((Sound) adapter.getItem(index)).getMpsound()) + ".mp3");
OutputStream os = new FileOutputStream(outputFile);
os.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", outputFile));
share.putExtra(Intent.EXTRA_TEXT, "\"" + ((Sound) adapter.getItem(index)).getTitre_show() + "\" shared by my app");
startActivity(Intent.createChooser(share, "Share Sound File"));
return true;
Есть идеи?