【发布时间】: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