Sharing text with image to instagram using android intent

China☆狼群 提交于 2020-12-29 05:42:33

问题


I know that this question has been asked several times before, I am trying to add caption to image shared to instagram using send intent

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"YOUR TEXT TO SHARE IN INSTAGRAM");
shareIntent.setPackage("com.instagram.android");
return shareIntent;

Has someone ever managed to make it work?

Is it not supported or has the support been revoked?


回答1:


There was an official statement from Instagram (mid-2015) announcing that pre-populated captions would no longer be accepted in the iOS and Android apps:

Beginning today, the iOS Hooks and Android Intents will stop accepting captions passed by third party apps. This is a non-breaking change: existing mobile apps that utilize pre-filled captions will continue to be able to use this flow to share media through the Instagram apps, but now Instagram will ignore the caption text. To create a caption for a photo or video shared by a third party app, users will have to enter a caption manually, the same way they already do when sharing content using the Instagram native apps.

Looking at the Instagram documentation for Android, indeed we see that there's no mention of providing the conventional Intent.EXTRA_TEXT string extra in the intent as is customary for other apps. Their sample is limited to only providing a Uri:

// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);

// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));

I'm sorry to say that it simply isn't possible, and we're at the discretion of Facebook in making this decision.




回答2:


Until it`s not solved by Instagram, I copy the text to the clipboard and instruct the user to paste it




回答3:


 @Override
public void onSingleImageSelected(Uri uri, String tag) {
    fileProfileImage = uri.getPath();
    compressProfileImage();
    imgShareTosocial.setVisibility(View.VISIBLE);
    Glide.with(getApplicationContext()).load(uri).into(imgShareTosocial);

}

@SuppressLint("CheckResult")
private void compressProfileImage() {
    File file = new File(fileProfileImage);
    new Compressor(this)
            .compressToFileAsFlowable(file)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<File>() {
                @Override
                public void accept(File file) throws Exception {

                    compressProfileImage = file;
                    String imagePath = compressProfileImage.getAbsolutePath();
                    tvSelectMedia.setText(imagePath);

                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                }
            });

}

private void shareToInstagram() {
    path = tvSelectMedia.getText().toString().trim();
    Intent intent = 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(MediaStore.Images.Media.insertImage(getContentResolver(), path, "Step Up", "Step Up")));
        } catch (FileNotFoundException e) {
            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);
    }
}



回答4:


I'm with the same problem. I think is not possible at this time.

In https://instagram.com/developer/mobile-sharing/android-intents/ only talk about Intent.EXTRA_STREAM, so i suppose that it's the only available.

Here is my code:

    Intent instagramIntent = new Intent(Intent.ACTION_SEND);
    instagramIntent.setType("image/*");
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);
    instagramIntent.putExtra(Intent.EXTRA_STREAM, uri);
    instagramIntent.setPackage("com.instagram.android");

    PackageManager packManager = getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(instagramIntent,  PackageManager.MATCH_DEFAULT_ONLY);

    boolean resolved = false;
    for(ResolveInfo resolveInfo: resolvedInfoList){
        if(resolveInfo.activityInfo.packageName.startsWith("com.instagram.android")){
            instagramIntent.setClassName(
                    resolveInfo.activityInfo.packageName,
                    resolveInfo.activityInfo.name );
            resolved = true;
            break;
        }
    }
    if(resolved){
        startActivity(instagramIntent);
    }else{
        Toast.makeText(PromocionarMain.this, "Instagram App is not installed", Toast.LENGTH_LONG).show();
    } 



回答5:


Instagram have stopped accepting pre-populated capitions to increase the quality of content in the system. See this post.

http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing



来源:https://stackoverflow.com/questions/32640765/sharing-text-with-image-to-instagram-using-android-intent

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