【问题标题】:How do you send an image to Facebook Messenger on Android using Intent.ACTION_SEND?如何使用 Intent.ACTION_SEND 将图像发送到 Android 上的 Facebook Messenger?
【发布时间】:2014-07-27 22:37:54
【问题描述】:

以下代码

final Intent sendImage = new Intent(Intent.ACTION_SEND);
sendImage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendImage.putExtra(Intent.EXTRA_STREAM, theUri);
sendImage.setType("image/png");
startActivity(Intent.createChooser(sendImage, "Send Image using "));

允许使用任何应用(例如 Dropbox、Gmail、普通消息/短信、Kik)发送图像,但不能使用 Facebook Messenger 应用。

每次我选择 Facebook Messenger 应用程序作为用于发送照片的应用程序时,我都会收到“抱歉,Messenger 无法立即处理此文件类型”异常。

Uri 就是通过这个方法得到的

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = new File(path, "Yogamoji!" + ".png");
FileOutputStream fileOutPutStream = new FileOutputStream(imageFile);
BitmapFactory.decodeStream(theAssets.open("emojis/" + fileName)).
compress(Bitmap.CompressFormat.PNG, 100, fileOutPutStream);

fileOutPutStream.flush();
fileOutPutStream.close();

return Uri.parse("file://" + imageFile.getAbsolutePath());

【问题讨论】:

  • 这很奇怪。如果他们不能处理它,他们不应该通过<intent-filter> 注册它。 theUri 到底是什么?
  • 文件路径 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);文件 imageFile = new File(path, "Image" + ".png"); FileOutputStream fileOutPutStream = new FileOutputStream(imageFile); BitmapFactory.decodeStream(theAssets.open(fileName))。压缩(Bitmap.CompressFormat.PNG,100,fileOutPutStream); fileOutPutStream.flush(); fileOutPutStream.close(); return Uri.parse("file://" + imageFile.getAbsolutePath());
  • flush()close() 之间,添加getFD().sync() 看看是否有帮助。另外,请使用Uri.fromFile() 而不是Uri.parse()
  • 我试过那个代码 Uri.fromFile(new java.io.File(imageFile.getAbsolutePath()));和 fileOutPutStream.flush(); fileOutPutStream.getFD().sync(); fileOutPutStream.close();但我仍然收到同样的错误消息
  • "我试过那个代码 Uri.fromFile(new java.io.File(imageFile.getAbsolutePath()));" -- 使用Uri.fromFile(imageFile)。这可能无济于事,但它比你现在做的更有效率。

标签: android facebook android-intent bitmap facebook-messenger


【解决方案1】:

我有类似的代码。唯一的区别是:

sendImage.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(uriFile));

File uriFile = new File(Environment.getExternalStorageDirectory()+folderName+imageName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-26
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2011-06-20
    相关资源
    最近更新 更多