gpt4 book ai didi

android - Android 中的照片分享 Intent

转载 作者:行者123 更新时间:2023-11-29 14:38:55 26 4
gpt4 key购买 nike

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

Uri uri = Uri.parse(pathToImage);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;

我用上面的代码在社交网站上分享图片。当我在 facebook 上发布图片时,只发布文本而图片没有出现。我们如何获取图片和 pathtoimage 是字符串变量我正在获取服务器图片路径并存储在字符串变量中。但它不起作用。请为我的上述问题提供任何解决方案。?

最佳答案

试试这个

Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));

引用更多链接

http://android-developers.blogspot.in/2012/02/share-with-intents.html

Android Share Via Dialog

Image post into facebook wall from android sdcard

关于android - Android 中的照片分享 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19218243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com