问题
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