feat: add local file management and incoming share support
This commit is contained in:
1 parent
731a83fcbc
commit
ed875ef2e1
43 files changed
+2674
-36
No files matched your search
@@ -23,6 +23,7 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<!-- 扫码绑定设备:相机实时扫码 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<!-- Android 13+ 从相册选取二维码图片 -->
|
||||
@@ -38,6 +39,7 @@
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:label="ttstd_family_care"
|
||||
android:name=".AppApplication"
|
||||
@@ -63,12 +65,32 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<!-- Receive files, media, links and text from the system sharesheet. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.files"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
<!-- 百度地图 AK -->
|
||||
<meta-data
|
||||
android:name="com.baidu.lbsapi.API_KEY"
|
||||
|
||||
@@ -50,6 +50,10 @@ public class MainActivity extends FlutterActivity {
|
||||
result.success(true);
|
||||
} else if (call.method.equals("requestLocalNetwork")) {
|
||||
requestLocalNetwork(result);
|
||||
} else if (call.method.equals("openLocalFile")) {
|
||||
openLocalFile(call.arguments(), result);
|
||||
} else if (call.method.equals("externalStorageRoot")) {
|
||||
result.success(android.os.Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||
} else if (call.method.equals("renderDeviceMarker")) {
|
||||
String title = call.arguments();
|
||||
result.success(DeviceMarkerRenderer.render(title));
|
||||
@@ -149,4 +153,31 @@ public class MainActivity extends FlutterActivity {
|
||||
* 1. 移除这里的贪婪拦截,让返回键事件传递给 Flutter 引擎。
|
||||
* 2. Flutter 首页通过 PopScope 处理返回,并通过 MethodChannel 调用 moveTaskToBack。
|
||||
*/
|
||||
private void openLocalFile(String path, MethodChannel.Result result) {
|
||||
try {
|
||||
if (path == null) throw new IllegalArgumentException("Missing path");
|
||||
java.io.File file = new java.io.File(path).getCanonicalFile();
|
||||
java.io.File root = android.os.Environment.getExternalStorageDirectory().getCanonicalFile();
|
||||
java.io.File inbox = new java.io.File(getFilesDir(), "Received").getCanonicalFile();
|
||||
boolean allowed = file.getPath().startsWith(root.getPath() + java.io.File.separator)
|
||||
|| file.getPath().startsWith(inbox.getPath() + java.io.File.separator);
|
||||
if (!allowed || !file.isFile() || !file.canRead()) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
Uri uri = androidx.core.content.FileProvider.getUriForFile(
|
||||
this, getPackageName() + ".files", file);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, getContentResolver().getType(uri));
|
||||
intent.setClipData(android.content.ClipData.newRawUri(file.getName(), uri));
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(intent);
|
||||
result.success(true);
|
||||
} catch (android.content.ActivityNotFoundException error) {
|
||||
result.success(false);
|
||||
} catch (java.io.IOException | RuntimeException error) {
|
||||
result.success(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="shared_storage" path="." />
|
||||
<files-path name="received_shares" path="Received/" />
|
||||
</paths>
|
||||
Reference in new issue
Block a user