几个月前,我曾被帮助创建一个应用程序,而我正试图让它自己发展,这并不像我想要的那么容易。
我想删除在下载目录中创建的文件。我将此文件夹用作缓存文件夹,以共享应用程序中存储的声音。这是股票期权的样本(工作正常,除非我不明白我应该把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;
任何想法 ?
由于您正在与其他应用共享文件,因此只有在其他应用读取您的文件后,您才能删除该文件。而且没有什么可以告诉您其他人已经完成了读取文件的工作。您可以批量删除。例如,您可以删除所有在当前时间之前1小时或更长时间共享的文件。但是为此,您必须创建文件,以便能够跟踪它们。您可以将所有文件保存在下载目录中的公用文件夹中,以轻松跟踪这些文件。如果您需要逻辑帮助和批量删除代码的帮助,请告诉我。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句