首页 > 解决方案 > 通过 Intent 在 Snapchat 中共享视频文件

问题描述

是否可以使用意图将视频文件从 Android 应用程序共享到 Snapchat?当我尝试下面的代码时,Snapchat 已打开,但没有共享视频文件的选项。

val file = File(context.cacheDir, filePath)
val uri = FileProvider.getUriForFile(context, context.applicationContext.packageName + ".share", file)

val snapchatIntent = Intent(Intent.ACTION_SEND)
snapchatIntent.setType("video/*")
snapchatIntent.putExtra(Intent.EXTRA_STREAM, uri)
snapchatIntent.component = ComponentName("com.snapchat.android", "com.snapchat.android.LandingPageActivity")
startActivity(snapchatIntent)

我像这样添加了提供者

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.share"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
</provider>

和文件路径:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="image" path="/"/>
    <cache-path name="video" path="/"/>
    <external-path name="external_files" path="."/>
</paths>

标签: androidkotlinandroid-intent

解决方案


推荐阅读