以Intent发送到邮件后删除文件.ACTION_SEND [英] Delete file after sent to mail as Intent.ACTION_SEND

查看:119
本文介绍了以Intent发送到邮件后删除文件.ACTION_SEND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

Uri screenshotUri = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
        intent.putExtra(Intent.EXTRA_SUBJECT, "Location of " + name);
        intent.putExtra(Intent.EXTRA_TITLE, getText(R.string.screen_share_message));
        intent.putExtra(Intent.EXTRA_TEXT, getText(R.string.screen_share_message));
        intent.setType("image/*");
        startActivity(Intent.createChooser(intent, "Share with"));

用户发送或共享文件后,如何删除它?

After user sends or share the file, How to delete it?

推荐答案

首先请参阅@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());
  }
}

这篇关于以Intent发送到邮件后删除文件.ACTION_SEND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆