使用android intent将文本与图像共享到instagram

时间:2015-09-17 22:11:26

标签: java android instagram sharing

我知道之前已经多次询问过这个问题,我正在尝试使用发送意图为Instagram共享图片添加标题

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;

有人曾设法让它发挥作用吗?

是否不支持或已取消支持?

5 个答案:

答案 0 :(得分:9)

There was an official statement from Instagram (mid-2015)宣布iOS和Android应用中不再接受预先填充的字幕:

  

从今天开始,iOS Hooks和Android Intents将停止接受第三方应用程序传递的字幕。这是一个非破坏性的变化:利用预填充字幕的现有移动应用程序将继续能够使用此流程通过Instagram应用程序共享媒体,但现在Instagram将忽略标题文本。要为第三方应用共享的照片或视频创建字幕,用户必须手动输入字幕,就像他们使用Instagram原生应用共享内容时一样。

关注the Instagram documentation for Android,我们确实没有提到在意图中提供常规Intent.EXTRA_TEXT字符串,这是其他应用程序的惯例。他们的样本仅限于提供Uri:

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

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

我很遗憾地说这根本不可能,我们可以自行决定Facebook做出这个决定。

答案 1 :(得分:5)

直到它没有被Instagram解决,我将文本复制到剪贴板并指示用户粘贴它

答案 2 :(得分:0)

我遇到同样的问题。我认为目前不可能。

https://instagram.com/developer/mobile-sharing/android-intents/中只讨论Intent.EXTRA_STREAM,所以我认为它是唯一可用的。

这是我的代码:

    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();
    } 

答案 3 :(得分:0)

Instagram已停止接受预先填充的标题,以提高系统内容的质量。看这篇文章。

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

答案 4 :(得分:0)

 @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);
    }
}