Instagram 分享问题:我总是收到“无法加载图片”的消息
Instagram sharing issue: Always I get the message “Unable to load image”
我正在开发共享功能
我的 Instagram 分享有问题
这是我的代码:
我正在尝试分享存储在 "drawable" 中的 "account" 图片 folder.This 只是一个示例
try {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse("android.resource://com.example.swathi.booklender/drawable/account");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
}catch (Exception e)
{
Toast.makeText(getActivity(),"No Activity available, install instagram",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
如何解决这个问题?
你不能直接共享drawable
首先从 drawable 创建一个文件然后分享它
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
File image = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(shareIntent, "Share image via"));
我正在开发共享功能
我的 Instagram 分享有问题
这是我的代码:
我正在尝试分享存储在 "drawable" 中的 "account" 图片 folder.This 只是一个示例
try { Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.parse("android.resource://com.example.swathi.booklender/drawable/account"); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setPackage("com.instagram.android"); startActivity(shareIntent); }catch (Exception e) { Toast.makeText(getActivity(),"No Activity available, install instagram",Toast.LENGTH_LONG).show(); e.printStackTrace(); }
如何解决这个问题?
你不能直接共享drawable
首先从 drawable 创建一个文件然后分享它
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
File image = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(shareIntent, "Share image via"));