从应用专用存储共享图像到Facebook [英] Sharing image from app private storage to Facebook

查看:145
本文介绍了从应用专用存储共享图像到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图采取一种非常通用的方法来提供共享选项,从我的应用程序的私人存储共享图像,但我遇到了一个问题,似乎是特定于共享图像到Facebook应用程序(com.facebook。 katana):


  1. 我将包含Uri的EXTRA_STREAM的意图发送到我应用程序私有目录中的图像。

  2. 通过ContentProvider,我可以通过在 openFile()中返回以下内容来提供对所需文件的访问:

      return ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY); 


  3. 分享到Facebook时,图像不会显示。然而,每个其他应用程序都可以正常工作将调用调用到我的ContentProvider,我看到Facebook确实查询了ContentProvider,并且 openFile()被命中。不过,图像不会出现。



解决方案

,我意识到我正在返回 null 作为MIME类型。我改变了 getType()的结果返回image / png,就是这样:Facebook接受了我的形象:

  @Nullable 
@Override
public String getType(@NonNull Uri uri){
//绝对必须提供MIME类型否则一些应用程序,如
// Facebook将简单地忽略该文件
returnimage / png;
}

我会指出你应该返回实际的MIME类型与Uri相关联的文件;我在这里返回PNG,因为我很懒,我知道我的所有图像都是这种类型。


I'm attempting to take a very generic approach in providing sharing options for sharing images from my app's private storage, but I've encountered a problem that appears to be specific to sharing images to the Facebook app (com.facebook.katana):

  1. I launch an intent with EXTRA_STREAM containing a Uri to an image inside the private directory of my app.
  2. Through a ContentProvider, I provide access to the desired file by returning the following in openFile():

    return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    

  3. When sharing to Facebook, the image doesn't appear. Every other app, however, does work. Debugging calls into my ContentProvider, I see that Facebook does indeed query the ContentProvider, and openFile() is hit. Nevertheless, the image doesn't appear.

解决方案

After much head scratching, I realized I was returning null as the MIME type. I changed the result of getType() to return "image/png", and that was it: Facebook accepted my image:

@Nullable
@Override
public String getType(@NonNull Uri uri) {
    // It's absolutely imperative that we provide the MIME type, otherwise some apps like
    // Facebook will simply ignore the file
    return "image/png";
}

I would point out that you should return the actual MIME type of the file associated with the Uri; I'm returning PNG here because I'm lazy, and I know that all my images are of that type.

这篇关于从应用专用存储共享图像到Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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