diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index c910ce3..d045dd5 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -48,6 +48,7 @@
+
@@ -56,6 +57,11 @@
android:scheme="haclient"
android:host="auth" />
+
+
+
+
+
new _MainPageState();
}
-class _MainPageState extends ReceiveShareState with WidgetsBindingObserver, TickerProviderStateMixin {
+class _MainPageState extends State with WidgetsBindingObserver, TickerProviderStateMixin {
StreamSubscription> _subscription;
StreamSubscription _stateSubscription;
@@ -22,6 +22,7 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
StreamSubscription _showPopupMessageSubscription;
StreamSubscription _reloadUISubscription;
StreamSubscription _showPageSubscription;
+ StreamSubscription _intentDataStreamSubscription;
int _previousViewCount;
bool _showLoginButton = false;
bool _preventAppRefresh = false;
@@ -40,7 +41,6 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
updateDeviceLocationIsolate,
isInDebugMode: false
);
- enableShareReceiving();
WidgetsBinding.instance.addObserver(this);
_firebaseMessaging.configure(
@@ -60,6 +60,13 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
_firebaseMessaging.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
+ _intentDataStreamSubscription = ReceiveSharingIntent.getTextStream().listen((String value) {
+ Logger.d("[SHARED] Got share from stream: $value");
+ _handleShare(value);
+ }, onError: (err) {
+ Logger.w("[SHARE] getLinkStream error: $err");
+ });
+
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid =
new AndroidInitializationSettings('mini_icon');
@@ -81,12 +88,6 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
_fullLoad();
}
- @override void receiveShare(Share shared) {
- if (shared.mimeType == ShareType.TYPE_PLAIN_TEXT) {
- _savedSharedText = shared.text;
- }
- }
-
Future onSelectNotification(String payload) async {
if (payload != null) {
Logger.d('Notification clicked: ' + payload);
@@ -131,12 +132,17 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
});
}
- _fetchData() async {
- if (_savedSharedText != null && !HomeAssistant().isNoEntities) {
- Logger.d("Got shared text: $_savedSharedText");
- Navigator.pushNamed(context, "/play-media", arguments: {"url": _savedSharedText});
- _savedSharedText = null;
+ _handleShare(String text) {
+ if (text != null && !HomeAssistant().isNoEntities) {
+ Navigator.pushNamed(context, "/play-media", arguments: {"url": text});
}
+ }
+
+ _fetchData() async {
+ ReceiveSharingIntent.getInitialText().then((String value) {
+ Logger.d("[SHARED] Got initial share: $value");
+ _handleShare(value);
+ });
await HomeAssistant().fetchData().then((_) {
_hideBottomBar();
if (_entityToShow != null) {
@@ -918,6 +924,7 @@ class _MainPageState extends ReceiveShareState with WidgetsBindingObse
_subscription?.cancel();
_showPageSubscription?.cancel();
_reloadUISubscription?.cancel();
+ _intentDataStreamSubscription?.cancel();
//TODO disconnect
//widget.homeAssistant?.disconnect();
super.dispose();
diff --git a/pubspec.yaml b/pubspec.yaml
index ae57437..989f46d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -30,9 +30,8 @@ dependencies:
workmanager: ^0.1.5
battery: ^0.3.1+1
sentry: ^2.3.1
- share:
- git:
- url: https://github.com/d-silveira/flutter-share.git
+ receive_sharing_intent: ^1.3.2
+
dev_dependencies:
flutter_test: