android - 将图像分享到 android 中的第三方应用程序

标签 android android-studio kotlin android-intent xiaomi

我正在尝试与 android 中的第三方应用程序共享图像。我可以与除小米(Android 12)和一加节点(Android 11)以外的所有设备共享图像。

 val shareIntent = Intent()
 shareIntent.action = Intent.ACTION_SEND
 shareIntent.putExtra(Intent.EXTRA_TEXT, shareText)
 shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri)
 shareIntent.type = "image/*"
 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
 context.startActivity(Intent.createChooser(shareIntent, "Share using"))
显示 toast 消息 --> 不支持此文件。

最佳答案

    val file = File(path, "${System.currentTimeMillis()}.png")
    file.outputStream().use {                 
           imageBitmap!!.compress(Bitmap.CompressFormat.PNG,100, it)
                }
    var imageUri = FileProvider.getUriForFile(
                    context,
                    BuildConfig.APPLICATION_ID + ".fileprovider",
                    file )

关于android - 将图像分享到 android 中的第三方应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73049740/

相关文章:

java - 电话间隙 : BluetoothChatExample [Android]

android - 重复构建失败 "To use Coroutine features, you must add ` ktx`......"

android - listFiles() 调用时出现 nullpointerException

java - 在 Android Studio 中使用 MapView 时 INSTALL_FAILED_MISSING_SHARED_LIBRARY

java - 错误 :Execution failed for task ':app:transformClassesWithMultidexlistForDebug' android studio

java - BottomSheet 中带有多个 ViewHolder 的 Kotlin RecyclerView

android - 调用 RILD 层函数在 android 中实现电话 session

android - 钛移动发布apk报错信息

java - 第二个 AsyncTask 没有执行

android - 如何将 lambda 作为 Intent 的额外内容传递?