Open story page of instagram to share image or video

时间:2017-05-16 09:35:24

标签: java android

I want to share my image into instagram story. Now I can open istagram easily like this , but this code show me the page that we share photo. I dont want this one, I want to open instagram story page just.

Here with this code:

try {
 Intent sharingIntent = new Intent(Intent.ACTION_SEND);
 File media = new File(path);
 Uri screenshotUri = Uri.fromFile(media);
 sharingIntent.setType("image/*");
 sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
 sharingIntent.setPackage("com.instagram.android");
 startActivity(sharingIntent);
} catch (Exception e) {
 e.printStackTrace();
 Toast.makeText(SavedActivity.this, "برنامه اینستاگرام یافت نشد.", Toast.LENGTH_LONG).show();

}

Is it possible to share directly into story of instagram?

2 个答案:

答案 0 :(得分:0)

这是不可能的(更不用说不良做法)。

您只能决定哪些应用程序可以处理您的意图,而不是它们在收到后对该意图的处理。

在代码库中对要发送的应用程序包进行硬编码也是不错的做法(即"com.instagram.android")。 Android documentation以及Instagram developers documentation建议您使用标准“选择器”模式分享照片。在这种情况下,用户将决定与哪个应用分享照片。

Intent share = new Intent(Intent.ACTION_SEND);
share.setType(type);

File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);

share.putExtra(Intent.EXTRA_STREAM, uri);

if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(Intent.createChooser(share, "Share to"));
} else {
    Toast.makeText(this, "No application to share with", Toast.LENGTH_SHORT).show();
}

除非这是个人项目(不会进入Google Play商店),否则我建议你坚持上述模式。

答案 1 :(得分:0)

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    Uri screenshotUri = Uri.parse(String.valueOf(dest));
    sharingIntent.setType("video/*");
    sharingIntent.setPackage("com.instagram.android");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    startActivity(Intent.createChooser(sharingIntent, "Share Video "));

我希望它可以帮助某人。