Search code examples
androidangularnativescriptnativescript-angular

is there a way to clear AppURL via handleOpenURL in Nativescript?


appURL values remain in the scope of app after it is suspended and then resumed.

I am trying to reset the values of appURL after it has been received in App Component initialized in Nativescript Application

import { handleOpenURL, AppURL } from 'nativescript-urlhandler';

ngOnInit() {
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL ', appURL);
var urlEncodedString = appURL.toString().split('out=')[1];
var json = JSON.parse(decodeURIComponent(urlEncodedString));
var token = json["token"].toString();
            }
}

or if it is possible to clear app Cache in Nativescript on app resume

Help! required


Solution

  • You may set the intent data to null once processed.

    handleOpenURL((appURL: AppURL) => {
     ...
     ...
     // Once you process the app url, set intent data to null
     if (application.android) {
         const activity = application.android.foregroundActivity || application.android.startActivity;
         if (activity) {
             const intent = activity.getIntent();
             if (intent) {
                 intent.setData(null);
             }
         }
      }
    });