您好,我有以下代码来共享图像:
// 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 的状态更新对话框,但没有附加图像,如果我尝试使用“测试”更新我的状态,它不起作用。没有错误。只是不工作。
我知道这不是图像,因为它正确上传到我的 Dropbox,我可以拉出图像并查看它。
我是否必须将图像附加到不同的意图才能与 Facebook 配合使用?
有任何想法吗?我正在物理设备上进行调试。
所以我找到了问题所在。
我使用 getFilesDir() 将图片保存到内部存储中,它将图片放入我的应用程序沙箱中,并使其他应用程序无法访问。
我用以下代码替换了我的代码:
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"));
现在工作得很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)