我在我的 android 应用程序中使用了 Instagram 集成。我的要求是将多张图片分享到一个帖子中。这是 Instagram 本身的新功能。
据我所知,instagram 只支持数据共享的意图解析。
Intent instagram = new Intent(android.content.Intent.ACTION_SEND);
instagram.setType("image/*");
instagram.putExtra(Intent.EXTRA_STREAM, uri);
instagram.putExtra(Intent.EXTRA_TEXT, "caption:goes here");
instagram.setPackage("com.instagram.android");
startActivity(instagram);
Run Code Online (Sandbox Code Playgroud)
我尝试将 parceable arraylist 用于多个 uri。
小智 0
Instagram不支持帖子中的多流(Feed)。只是卷轴或故事。您可以在此处查看Feed 的文档。这里是故事。
我对卷轴和故事的多个图像的实现
try {
val share = Intent(Intent.ACTION_SEND_MULTIPLE)
share.type = "image/*" //For a video "video/*"
share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, listUri)
share.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
context.startActivity(
Intent.createChooser(
share,
context.getString(R.string.share)
)
)
} catch (e: Exception) {
//Not installed Instagram open GP or dialog
}
Run Code Online (Sandbox Code Playgroud)
对于具有一张图像的 Feed
try {
val share = Intent(Intent.ACTION_SEND)
share.type = "image/*" //For a video "video/*"
putExtra(Intent.EXTRA_STREAM, uri)
share.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
context.startActivity(
Intent.createChooser(
share,
context.getString(R.string.share)
)
)
} catch (e: Exception) {
//Not installed Instagram open GP or dialog
}
Run Code Online (Sandbox Code Playgroud)
发送到 Instagram Feed 图像的方式。您需要将所有图像保存在图库中并将单张照片发送到 Instagram,然后用户自己选择图像
以及使用 Glide 从远程图像获取 Uri 的其他帮助 另外,将文本复制到剪贴板
Glide.with(context)
.asBitmap()
.load(imageUrl)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
getLocalBitmapUri(resource)?.let {
createInstagramIntent(it)
}
}
override fun onLoadCleared(placeholder: Drawable?) {}
})
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
val clip = ClipData.newPlainText("label", message)
clipboard?.setPrimaryClip(clip)
fun getLocalBitmapUri(bmp: Bitmap): Uri? {
return try {
val bmpUri: Uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val file = File(
context.filesDir.path,
"share_image_" + System.currentTimeMillis() + ".png"
)
FileOutputStream(file)
.use {
bmp.compress(Bitmap.CompressFormat.PNG, 100, it)
}
FileProvider.getUriForFile(context, context.packageName + ".fileprovider", file)
} else {
val file = File(
context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),
"share_image_" + System.currentTimeMillis() + ".png"
)
FileOutputStream(file).use {
bmp.compress(Bitmap.CompressFormat.PNG, 100, it)
}
Uri.fromFile(file)
}
bmpUri
} catch (e: IOException) {
e.printStackTrace()
null
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
564 次 |
| 最近记录: |