安卓:分享图片的意图不是工作在Facebook? [英] Android: Share Image intent not working with Facebook?
问题描述
您好我有以下的code共享图像:
Hi I have the following code to share an image:
// Share
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Uri uri = Uri.parse(getFilesDir() + File.separator + "myGoal.jpg");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image"));
它的工作原理共享图像Dropbox的,但如果我选择了Facebook的选项,我得到Facebook的状态更新对话框,没有附加的图像,如果我尝试更新我与'测试'状态这是行不通的。没有错误。只是不工作。
It works to share the image to Dropbox but if I pick the Facebook option, I get Facebook's status update dialog with no image attached and if I try to update my status with 'Test' it doesn't work. No errors. Just not working.
我知道这是不是图像,因为它上传到我的Dropbox的正确,我可以拉起来的形象,看它。
I know it's not the image because it uploads to my Dropbox properly and I can pull up the image and look at it.
我必须将图像连接到不同的意图它与Facebook的工作?
Do I have to attach the image to the intent differently for it to work with Facebook?
任何想法?我调试一个物理设备上。
Any ideas? I'm debugging on a physical device.
推荐答案
所以我想通了这个问题。
So I figured out the problem.
我保存图片到内部存储器与getFilesDir(),它把图片放到我的应用程序沙箱中,并取得了无法访问其他应用程序。
I was saving the picture to internal storage with getFilesDir() which put the picture into my apps sandbox and made inaccessible to the other apps.
我代替我的code具有以下内容:
I replaced my code with the following:
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/MyApp/";
File dir = new File(file_path);
dir.mkdirs();
File file = new File(dir, "myPic.png");
FileOutputStream fOut = new FileOutputStream(file);
screenshot.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
// Share
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
share.putExtra(Intent.EXTRA_TEXT, "My Image");
startActivity(Intent.createChooser(share, "Share Image"));
工作完全正常了。
Works perfectly fine now.
这篇关于安卓:分享图片的意图不是工作在Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!