How to share image to Snapchat from my android app?

假装没事ソ 提交于 2020-02-05 03:55:07

问题


I'm adding share feature in my app, and everything works fine except sharing to Snapchat. When I send "SEND" intent Snapchat only opens it own camera preview and my picture is lost. I tried different things, but nothing helps. Also when I share via standard Android sharing screen, Snapchat successfully opens it. So here is my code:

 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

I use 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>

And such paths:

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

Can you help me please to figure out what is the problem? Thanks for all the answers!


回答1:


Some app (like Snapchat) use unobvious way of accepting sent Media, so you should set to your intent component:

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


来源:https://stackoverflow.com/questions/51358268/how-to-share-image-to-snapchat-from-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!