我在我的应用程序中添加了共享功能,除了与Snapchat共享外,其他所有功能都正常运行。当我发送“发送”意图时,Snapchat仅打开其自己的相机预览,而我的照片丢失。我尝试了不同的方法,但没有任何帮助。同样,当我通过标准的Android共享屏幕进行共享时,Snapchat会成功打开它。所以这是我的代码:

 var tempFile = File(filePath)
        val sharingIntent = Intent(Intent.ACTION_SEND)
        sharingIntent.type = "image/jpg"
        sharingIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
        val image = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, tempFile)
        sharingIntent.putExtra(Intent.EXTRA_STREAM, image)
        sharingIntent.`package` = "com.snapchat.android"
        return sharingIntent


我使用FileProvider:

  <provider
        android:name="android.support.v4.content.FileProvider"
        android:grantUriPermissions="true"
        android:exported="false"
        android:authorities="${applicationId}">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_provider_path"/>
    </provider>


以及这样的路径:

<paths>
<cache-path name="cache" path="/" />




您能帮我找出问题所在吗?
感谢所有的答案!

最佳答案

某些应用程序(例如Snapchat)使用不明显的方式来接收已发送的媒体,因此您应将其设置为Intent组件:

intentComponent = ComponentName("com.snapchat.android", "com.snapchat.android.LandingPageActivity")
intent.component = intentComponent
//use component instead of setting package

07-27 13:22