Instagram分享问题:有时我收到消息"无法加载图片"

Chi*_*mar 9 android android-intent instagram

我正在使用社交应用程序的共享功能Intent.

我在Instagram上分享图片时遇到问题.

有时我收到消息

无法加载图片.

这是我的代码:

String path="content://media/external/images/media/32872";

Intent shareIntent = new Intent();
shareIntent.setType("image/jpeg");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
Run Code Online (Sandbox Code Playgroud)

我该如何摆脱这个问题?

Nul*_*yte 5

如果您有文件,则使用以下代码共享图像,

private void shareIntagramIntent(String path) {
        Intent intent = getActivity().getPackageManager()
                .getLaunchIntentForPackage("com.instagram.android");
        if (intent != null) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setPackage("com.instagram.android");
            try {
                shareIntent.putExtra(Intent.EXTRA_STREAM,
                        Uri.parse("file://" + path));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            shareIntent.setType("image/jpeg");

            startActivity(shareIntent);
        } else {
            // bring user to the market to download the app.
            // or let them choose an app?
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id="
                    + "com.instagram.android"));
            startActivity(intent);
        }
    }
Run Code Online (Sandbox Code Playgroud)

  • 今天我在 Instagram 上遇到了同样的问题,但上面的代码对我有用。这很重要 Uri.parse("file://" + path)。 (2认同)

小智 0

尝试这个:

\n\n
File filepath = Environment.getExternalStorageDirectory(); \ncacheDir = new File(filepath.getAbsolutePath() + "/LikeIT/"); \ncacheDir.mkdirs(); \nIntent intent = new Intent(); \nintent.setType("image/*");     \nintent.setAction(Intent.ACTION_SEND); \nintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filepath.getAbsolutePath())); \nactivity.startActivity(intent);\xc2\xa0\xc2\xa0\n
Run Code Online (Sandbox Code Playgroud)\n