【问题标题】:Android Share Image Doesn't Clear the Preview from a previously shared itemAndroid 共享图像不会从以前共享的项目中清除预览
【发布时间】:2015-05-07 04:29:48
【问题描述】:

简单的问题,我设置了代码来创建图像的位图并通过 Action_Send 共享它。共享时,会发送正确的图像,但显示在消息字段中的图像预览(如果您通过文本发送)显示以前共享的项目。有什么办法可以强制刷新预览吗?下面是一张图片,显示了我正在谈论的领域。那里的预览不是当前共享的图像,而是许多共享中的以前从未清除过的图像。

http://i.stack.imgur.com/dT78Z.png

private Intent getShareIntent() 
{ 
Intent shareIntent = new Intent(Intent.ACTION_SEND); 
File sdCard = Environment.getExternalStorageDirectory(); 
File sharedFile = new File(sdCard+"/SaveDirectory/mypicture.png"); 
Uri uri = Uri.fromFile(sharedFile);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); return shareIntent; 
}

【问题讨论】:

  • 私有 Intent getShareIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND);文件 sdCard = Environment.getExternalStorageDirectory();文件 sharedFile = new File(sdCard+"/SaveDirectory/mypicture.png"); Uri uri = Uri.fromFile(sharedFile); shareIntent.setType("image/*");shareIntent.putExtra(Intent.EXTRA_STREAM, uri);返回共享意图;抱歉这段代码太乱了,在手机上
  • 我修复了代码,现在应该看起来更好一点了。有什么想法吗?

标签: java android android-intent


【解决方案1】:

我看到了同样的问题。这个问题只存在于少数应用,比如谷歌的keep、g+等应用。

如果文件相同,这些应用会保留预览。不知道他们为什么做出这样的假设。简而言之,预览是按文件保留的,即使在文件更改后也不会更新。我们无法修复这些应用,因此解决方案是避免更新同一个文件。

使用File.createTempFile() 创建一个临时文件,以确保创建一个新的唯一文件。这样预览就会更新。

就我而言,我在缓存目录(getCacheDir() 或 getExternalCacheDir())中创建了这些临时文件,并在 onDestroy() 上清除缓存。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多