1 year ago

#352699

test-img

Balaji murugesan

Got error in whatsapp while sharing video in android

Showing error like this when sharing videos in whatsapp

'The following is my code to share document,image and videos.The image and document are sharing with no issues ,the issue only occurs while sharing video in to whatsapp.'

  shareFileUri=uriFromFile(context,File(path))
                    val shareIntent = Intent(Intent.ACTION_SEND)
                    shareIntent.type = "*/*"
                    shareIntent.putExtra(Intent.EXTRA_STREAM,  shareFileUri)
                    shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
                  // shareIntent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                    shareIntent.flags=Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                    // shareIntent.type = "application/*"
                    // context.startActivity(Intent.createChooser(shareIntent, "share.."))
                    val chooser = createChooser(shareIntent, "Share File")

                    val resInfoList: List<ResolveInfo> = context.packageManager
                        .queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY)

                    for (resolveInfo in resInfoList) {
                        val packageName: String = resolveInfo.activityInfo.packageName
                        context.grantUriPermission(
                            packageName,
                            shareFileUri,
                            FLAG_GRANT_WRITE_URI_PERMISSION or FLAG_GRANT_READ_URI_PERMISSION
                        )
                    }

                    context.startActivity(chooser)

'get uri path'

fun uriFromFile(context:Context, file:File):Uri {

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        FileProvider.getUriForFile(context.applicationContext, BuildConfig.APPLICATION_ID + ".provider", file)
    } else {
        Uri.fromFile(file)
    }
}

'This is my file provider in manifest '

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

'The following is the xml path for file provider'

<paths>

<files-path
    name="internal_files"
    path="."/>
<external-files-path
    name="external_files_path"
    path="."/>

android

kotlin

android-contentprovider

0 Answers

Your Answer

Accepted video resources