• Resolved tamerkilinc

    (@tamerkilinc)


    Hi everyone,

    This questions has been asked by someone but not really solved.

    I have created a native Android app with the content of the mobile version of the website bistro-proseven.de using Cordova. The app is working fine on my device and receiving push notifications via OneSignal.

    My problem is that when I post a new blogpost and the app receives a push notification, when I click the notification the browser opens the post. But I want the app to open the post.

    I found out that I have to unset the URL parameter and add a new key. So I pasted this code on my websites header file:

    <?php
    function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
    {
        $fields['isAndroid'] = true;
        $fields['isIos'] = true;
        $fields['isAnyWeb'] = false;
        $fields['isChrome'] = false;
        $fields['data'] = array(
            "myappurl" => $fields['url']
        );
        /* Unset the URL to prevent opening the browser when the notification is clicked */
        unset($fields['url']);
        return $fields;
    }
    

    This code is from OneSignal Team and has been posted somewhere else when someone had a similar problem. So what the code does is saying that URL will be unset and myappurl will be the new additional data key.

    My quesion is: How can I tell my app now to read the myappurl key and open the blogpost in my app instead of opening in the browser?

    Thank you in advance!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey @tamerkilinc,

    Great question! It looks like you have a good start with the code above. Please see https://documentation.onesignal.com/docs/wordpress#section-opening-web-and-mobile-notifications-in-the-browser-and-app for some links on how to add the other half of the code from your native app to intercept the notification and read the “myappurl” field from “data”.

    (see docs for links)

    Use the mobile notification opened / notification clicked handler to navigate the user to a section in your app.

    Here is an example using native Android. Here is the documentation for the native notificationOpened handler used by the example.

    If you’re using Cordova, Phonegap, or Ionic, be sure to use the notificationOpened handler from the Cordova, Phonegap, or Ionic section of our docs . On the code example, be sure to click the variant describing how to open a page in your app.

    Hi @onesignal,

    I have created a mu-plugin with mobile and browser notification option. In web, everything works well, but when it’s come to mobile notification nothing happens. Notifications open just the app, not the URL. My app is a web-view app too.

    Any advice?

    @salihaksu @tamerkilinc do you come up with a solution as I face the same problem (web view app juste open the app without redirection to the url in the notification)

    @onesignal i have read the doc in your link but i still cannot found the solution.
    Do you have other solution or tutorial please?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to open push notifications in app instead of browser?’ is closed to new replies.