Open Instagram app from another android app and send an Image with a Caption

和自甴很熟 提交于 2019-12-21 02:25:05

问题


What I basically looking for is to open Instagram app from another app and send an Image with a caption. There is some useful documentation to do this in iOS. (iPhone-hooks)

Do Instagram support to perform custom actions in Android like in iOS as described in iPhone-hooks?

Below is the current code used in my application to perform this task partially.

private void sendImageToIntagram(Activity activity) {
    Intent intent = activity.getPackageManager().getLaunchIntentForPackage("com.instagram.android");
    if (intent != null) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setPackage("com.instagram.android");
        String imagePath = ImageUtil.getProcessedImage().getAbsolutePath();
        try {
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(activity.getContentResolver(), imagePath, "Title", "Description")));
            // shareIntent.putExtra(Intent.EXTRA_TITLE,  "Caption 01");
            // shareIntent.putExtra(Intent.EXTRA_TEXT,   "Caption 02");
            // shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Caption 03");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        shareIntent.setType("image/jpeg");
        activity.startActivity(shareIntent);
    } else {
        // bring user to the market to download the app.

        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=" + "com.instagram.android"));
        activity.startActivity(intent);
    }
}

None of the above Title, description, Caption 01, Caption 02, Caption 03 worked.

Then I tried with,

shareIntent.setAction(Intent.ACTION_SEND); --> shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);

and,

shareIntent.setType("image/jpeg");
shareIntent.setType("image/*");
shareIntent.setType("*/*"); 

too, but none of the above worked also.


回答1:


Looking at this question, and in particular to this answer by Chriskot, it looks that since July 2014 Instagram lets you do this.

Long story short

Intent instagram = new Intent(android.content.Intent.ACTION_SEND);  
instagram.setType("image/*");
instagram.putExtra(Intent.EXTRA_STREAM, [URI of photo]);
instagram.putExtra(Intent.EXTRA_TEXT, [Text of caption]);
instagram.setPackage(instagramPackageName);   
startActivity(instagram);



回答2:


Short answer, No.

Instagram doesn't have an Android equivalent to iPhone-hooks.

They do support the ACTION_SEND but only take into account the Intent.EXTRA_STREAM on their end.

Unless something changed in the past 4 months (I doubt it) that this guy took a stub on their code, from their AndroidManifest.xml you can assume, by looking in their intent catcher Activity that they only care for android.intent.extra.STREAM.

So for now, you can't send any other data than the actual image.



来源:https://stackoverflow.com/questions/19290779/open-instagram-app-from-another-android-app-and-send-an-image-with-a-caption

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!