ReX*_*357 3 java android facebook android-intent
嗨,我有以下代码来共享图像:
// 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"));
Run Code Online (Sandbox Code Playgroud)
它可以将图像分享到Dropbox,但是如果我选择了Facebook选项,我会获得Facebook的状态更新对话框,没有附加图像,如果我尝试用"测试"更新我的状态,它就不起作用.没有错误.只是不工作.
我知道这不是图像,因为它正确地上传到我的Dropbox,我可以拉出图像并查看它.
我是否必须以不同方式将图像附加到意图才能与Facebook一起使用?
有任何想法吗?我正在物理设备上调试.
ReX*_*357 10
所以我想出了问题所在.
我使用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"));
Run Code Online (Sandbox Code Playgroud)
现在工作得非常好.
归档时间: |
|
查看次数: |
7109 次 |
最近记录: |