使用Intent将多个图像发布到Instagram [英] Posting Multiple Images to Instagram using Intents

查看:100
本文介绍了使用Intent将多个图像发布到Instagram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Instagram允许通过Android Intents以编程方式从Android应用程序上传单个图像或视频.我已经能够成功做到这一点.我想知道的是,Instagram是否可以使用Intent处理多个图像?不幸的是,没有太多甚至没有任何信息.以下是我最后的尝试,即短暂打开Instagram,然后关闭并显示一条吐司消息无法加载图像".

Instagram allows a single image or video to be uploaded programmatically from an Android app via Android Intents. I have been able to do this successfully. What I want to know is it possible for Instagram to handle multiple images using Intents? Not much to no information on this unfortunately. The following is my last attempt which opens Instagram briefly then closes with a toast message saying "Unable to load image".

尝试过Intent.ACTION_SEND和Intent.ACTION_SEND_MULTIPLE

Have tried both Intent.ACTION_SEND and Intent.ACTION_SEND_MULTIPLE

val fileUris = ArrayList<Uri>()

val newFile = File("/data/user/0/com.myapp.android/files/media/961087022.jpg")
val contentUri = getUriForFile(this, "com.myapp.fileprovider", newFile)

grantUriPermission("com.instagram.android", contentUri, FLAG_GRANT_READ_URI_PERMISSION)
fileUris.add(contentUri)

val newFile2 = File("/data/user/0/com.myapp.android/files/media/961146948.jpg")
val contentUri2 = getUriForFile(this, "com.myapp.fileprovider", newFile2)

grantUriPermission("com.instagram.android", contentUri2, FLAG_GRANT_READ_URI_PERMISSION)
fileUris.add(contentUri2)

val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "image/*"
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris)
shareIntent.`package` = "com.instagram.android"
startActivity(Intent.createChooser(shareIntent, "Share to"))

推荐答案

我一直在寻找如何将多个视频文件共享到instagram故事中..阅读

I was looking on how to share multiple video files to instagram stories.. I couldn't find how to do it reading the facebook documentation.

相反,我设置了发送多个文件的意图,并将意图包设置为"com.instagram.android",而且令人惊讶的是它起作用了.

Instead i set the intent to send multiple files and set the intent package to "com.instagram.android", and surprisingly it worked..

  Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE) ;
                            share.setType("video/*");
                            share.putExtra(Intent.EXTRA_SUBJECT, "abc");
                            share.putExtra(Intent.EXTRA_TITLE, "abcd");

                            ArrayList<Uri> files = new ArrayList<Uri>();

                            for (String path : filesToSend) {
                                File myFiles = new File(path);
                                Uri doneUri = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
                                        BuildConfig.APPLICATION_ID + ".provider", myFiles);
                                files.add(doneUri);
                            }

                            share.setPackage("com.instagram.android");
                            share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
                            startActivity(share);

希望,这会有所帮助!

这篇关于使用Intent将多个图像发布到Instagram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆