From 702c8ec73d040b0fca4c97d5a34702aca2f18fa2 Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Thu, 1 May 2025 10:42:42 +0530 Subject: [PATCH] [client] Add receive_sharing_intent, upgrade gradle and ndk --- client/android/app/build.gradle | 14 +++++++- .../android/app/src/main/AndroidManifest.xml | 12 +++++++ .../gradle/wrapper/gradle-wrapper.properties | 2 +- client/android/settings.gradle | 2 +- client/lib/ui/explorer/explorer_view.dart | 34 +++++++++++++++++++ client/pubspec.lock | 8 +++++ client/pubspec.yaml | 1 + 7 files changed, 70 insertions(+), 3 deletions(-) diff --git a/client/android/app/build.gradle b/client/android/app/build.gradle index 4157c4a0..3c13ce9d 100644 --- a/client/android/app/build.gradle +++ b/client/android/app/build.gradle @@ -8,7 +8,7 @@ plugins { android { namespace = "cloud.phylum.drive" compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion + ndkVersion = "27.0.12077973" compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -40,6 +40,18 @@ android { } } +project(':receive_sharing_intent').afterEvaluate { + project(':receive_sharing_intent').android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + } + } +} + flutter { source = "../.." } diff --git a/client/android/app/src/main/AndroidManifest.xml b/client/android/app/src/main/AndroidManifest.xml index cf83d0c4..e525aad3 100644 --- a/client/android/app/src/main/AndroidManifest.xml +++ b/client/android/app/src/main/AndroidManifest.xml @@ -30,6 +30,18 @@ + + + + + + + + + + + + diff --git a/client/android/gradle/wrapper/gradle-wrapper.properties b/client/android/gradle/wrapper/gradle-wrapper.properties index 5d6560a4..e4ef43fb 100644 --- a/client/android/gradle/wrapper/gradle-wrapper.properties +++ b/client/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip diff --git a/client/android/settings.gradle b/client/android/settings.gradle index a4a00212..a14cb837 100644 --- a/client/android/settings.gradle +++ b/client/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.3.0" apply false + id "com.android.application" version "8.9.0" apply false id "org.jetbrains.kotlin.android" version "2.1.0" apply false } diff --git a/client/lib/ui/explorer/explorer_view.dart b/client/lib/ui/explorer/explorer_view.dart index 5f780dde..f7ba33c4 100644 --- a/client/lib/ui/explorer/explorer_view.dart +++ b/client/lib/ui/explorer/explorer_view.dart @@ -1,8 +1,11 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:phylum/ui/explorer/explorer_actions.dart'; import 'package:phylum/ui/explorer/explorer_gesture_handler.dart'; import 'package:phylum/ui/explorer/path_view.dart'; import 'package:provider/provider.dart'; +import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import 'explorer_controller.dart'; import 'folder_empty_view.dart'; @@ -19,6 +22,37 @@ class ExplorerView extends StatefulWidget { class _ExplorerViewState extends State { final _refreshKey = GlobalKey(); + late StreamSubscription _intentSub; + + @override + void initState() { + super.initState(); + + // Listen to media sharing coming from outside the app while the app is in the memory. + _intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) { + final files = value.map((f) => f.path).toList(growable: false); + print('Received files when in memory'); + print(files); + ReceiveSharingIntent.instance.reset(); + }, onError: (err) { + print("getIntentDataStream error: $err"); + }); + + // Get the media sharing coming from outside the app while the app is closed. + ReceiveSharingIntent.instance.getInitialMedia().then((value) { + final files = value.map((f) => f.path).toList(growable: false); + print('Received files when closed'); + print(files); + ReceiveSharingIntent.instance.reset(); + }); + } + + @override + void dispose() { + _intentSub.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { return ExplorerActions( diff --git a/client/pubspec.lock b/client/pubspec.lock index 97b82008..9e05a671 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -905,6 +905,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + receive_sharing_intent: + dependency: "direct main" + description: + name: receive_sharing_intent + sha256: ec76056e4d258ad708e76d85591d933678625318e411564dcb9059048ca3a593 + url: "https://pub.dev" + source: hosted + version: "1.8.1" share_plus: dependency: "direct main" description: diff --git a/client/pubspec.yaml b/client/pubspec.yaml index eb03c0dd..d43213b6 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: permission_handler: printing: provider: + receive_sharing_intent: share_plus: sqlite3: state_notifier: