OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
625 stars 214 forks source link

The addClickListener method is not launching my application. #809

Closed beytt06 closed 7 months ago

beytt06 commented 11 months ago

How can we help?

I use OneSignal for receiving notifications both in my browser and mobile application. Therefore, the incoming notification contains a URL key. What I want to achieve is to launch my application without asking the user to "Open with" when the notification is clicked on Android or iOS. Here are my manifest codes:

        meta-data   android:name="com.onesignal.suppressLaunchURLs" android:value="true" />
         meta-data android:name="com.onesignal.open_urls_in_app" android:value="true"/>

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" android:host="mywebsite.com" />
            <data android:scheme="https" android:host="mywebsite.com" />
        </intent-filter>

Additionally, here are my addClickListener codes:

OneSignal.Notifications.addClickListener((event) {
        Map<String, dynamic>? customData = event.notification.rawPayload;
        if (customData != null && customData.containsKey('custom')) {
          String customValue = customData['custom'];
          try {
            var decodedData = jsonDecode(customValue);
            var url = decodedData['u'];
            if (url != null) {
              Uri parsedUrl = Uri.parse(url);
              if (parsedUrl.host == 'mywebsite.com') {
                if (parsedUrl.path == '/advance') {
                  Helper.navigatePush(context, AdvanceMainScreen());
                } else if (parsedUrl.path == '/dashboard') {
                  late ChatNewProvider _chatNewProvider;
                  var chatId = parsedUrl.queryParameters['chat'];
                  var groupId = parsedUrl.queryParameters['group'];
                  Future.delayed(Duration.zero, () async {
                    _chatNewProvider = Provider.of<ChatNewProvider>(context, listen: false);
                    await _chatNewProvider.fetchMessages();
                    var find = _chatNewProvider.searchOnmessages.firstWhereOrNull((e) =>
                    e.from_id == int.parse(chatId ?? "0") ||
                        e.group_id == groupId);
                    if (context.mounted && find != null) {
                      Helper.navigatePush(context, ChatMessageScreen(message: find));
                    }
                  });
                }
              }
            }
          } catch (e) {
            print("Error: $e");
          }
        }
      });

However, I couldn't find an update related to this. I would appreciate it if you could assist me.

Code of Conduct

jennantilla commented 7 months ago

Hi @beytt06 apologies that this issue was missed. Are you still having problems with this?

You can suppress default processing of the launch URLs to handle them programmatically. Here is some more information on that.

If that doesn't fit your use case or you have any additional questions or concerns, please let us know!