有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用安卓 intent将文本和图像共享到instagram

我知道这个问题已经被问过好几次了,我正在尝试使用send intent为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.安卓");
return shareIntent;

有没有人能做到这一点

它是否不受支持或支持已被撤销


共 (5) 个答案

  1. # 1 楼答案

     @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);
        }
    }
    
  2. # 2 楼答案

    在Instagram无法解决之前,我会将文本复制到剪贴板,并指示用户粘贴

  3. # 4 楼答案

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

    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.

    看看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自行决定

  4. # 5 楼答案

    我也有同样的问题。我认为目前不可能

    https://instagram.com/developer/mobile-sharing/android-intents/中,只谈论意图。额外的流,所以我想这是唯一可用的

    这是我的代码:

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