且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以Intent发送到邮件后删除文件.ACTION_SEND

更新时间:2023-02-11 18:11:44

首先请参阅@DheerajV.S.答案.

First Refer @Dheeraj V.S. answer.

要删除文件的方式

  1. 您可以使用后台运行的服务删除这些文件.服务检查文件夹中是否包含任何文件,然后在服务中写入逻辑,以便它将删除文件.

  1. You can delete these files using service which run in background. Service check whether folder contain any file then write logic in service such that it will delete the files.

您可以在启动应用程序时删除这些文件.意味着如果特定文件夹中存在任何文件,那么在开始欢迎活动时,您可以添加逻辑来删除文件.

You can delete these files on starting the your application. Means if any files exist in particular folder so in starting welcome activity you can put logic to delete file.

//要删除隐藏的文件

try {
      new Helper().deleteFromExternalStorage(".photo.jpg");
}
catch(Exception e){
      Log.v("APP","Exception while deleting file");
}

从外部存储删除文件的方法

Method to delete file from external storage

public void deleteFromExternalStorage(String fileName) {
  String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/directoryname";
  try
  {
    File file = new File(fullPath, fileName);
    if(file.exists())
        file.delete();
  }
  catch (Exception e)
  {
    Log.e("APP", "Exception while deleting file " + e.getMessage());
  }
}