fix:修复 android 无法分享文件的问题
This commit is contained in:
parent
5b09b91c84
commit
3ae670fbee
@ -62,9 +62,10 @@
|
||||
android:label="@string/app_name"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
|
||||
@ -68,21 +68,22 @@ class MainActivity : FlutterActivity() {
|
||||
if (filePath == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val file = File(filePath)
|
||||
if (!file.exists()) {
|
||||
Log.e("File Share", "文件不存在: $filePath")
|
||||
return
|
||||
}
|
||||
val uri: Uri = FileProvider.getUriForFile(
|
||||
this,
|
||||
"${applicationContext.packageName}.fileprovider",
|
||||
"${packageName}.provider",
|
||||
file
|
||||
)
|
||||
|
||||
val shareIntent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
type = "application/octet-stream"
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
|
||||
startActivity(Intent.createChooser(shareIntent, null))
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<files-path name="files" path="." />
|
||||
<paths>
|
||||
<root-path name="root-path" path="."/>
|
||||
<files-path name="files" path="."/>
|
||||
<cache-path name="cache" path="."/>
|
||||
<external-files-path name="external_files" path="."/>
|
||||
</paths>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user