Skip to content

Commit

Permalink
[receive] Androidで受信完了後に開くアプリを選択できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreNion committed Jul 9, 2024
1 parent f73faed commit f810fa6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ class MainActivity: FlutterActivity() {
result.success(null)
} else if (call.method == "openFileManager")
{
// PATHを送っているが、デフォルトアプリへの受け渡しは厳しそうなので保留中
// val path = call.argument<String>("path")
val openMediaApp = call.argument<Boolean>("media")
val path = call.argument<String>("path")
if (path == null || openMediaApp == null) {
result.error("NEED_ARGS", null, null)
return@setMethodCallHandler
}

// PATHのデフォルトアプリへの受け渡しは厳しそうなので保留中
val intent = Intent(Intent.ACTION_VIEW)
intent.setType("resource/folder")
if (openMediaApp) {
intent.setType("image/*")
} else {
intent.setType("resource/folder")
}
startActivity(intent);
} else {
result.notImplemented()
Expand Down
36 changes: 33 additions & 3 deletions lib/provider/receive_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Future<void> startReceive(TruckerDevice device, WidgetRef ref) async {
size: const Size(40, 40),
child: const Icon(Icons.check, color: Colors.green)),
title: (_) => const Text("ファイルの受信が完了しました!"),
subtitle: (_) => const Text("ディレクトリを開くには、ここをタップしてください。"),
subtitle: (_) => const Text("ファイルを開くには、ここをタップしてください。"),
trailing: (_) => const Icon(Icons.folder_open),
duration: const Duration(seconds: 10),
onTap: () {
Expand All @@ -137,8 +137,38 @@ Future<void> startReceive(TruckerDevice device, WidgetRef ref) async {
} else if (Platform.isAndroid) {
// PATHを送っているが、デフォルトアプリへの受け渡しは厳しそうなので保留中
const platform = MethodChannel('dev.cnion.filetrucker/mediastore');
platform.invokeMethod(
'openFileManager', {"path": dirPath, "media": false});
BotToast.showWidget(toastBuilder: (cancelFunc) {
return AlertDialog(
title: const Text("開くアプリの種類を選択...", textAlign: TextAlign.center),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Column(children: [
IconButton(
onPressed: () {
cancelFunc();
platform.invokeMethod("openFileManager",
{"path": dirPath, "media": true});
},
icon: const Icon(Icons.perm_media, size: 70)),
const Text("写真アプリ")
]),
Column(children: <Widget>[
IconButton(
onPressed: () {
cancelFunc();
platform.invokeMethod("openFileManager",
{"path": dirPath, "media": false});
},
icon: const Icon(Icons.file_copy, size: 70)),
const Text("ファイル管理アプリ")
])
],
),
],
);
});
}
},
);
Expand Down

0 comments on commit f810fa6

Please sign in to comment.