hypery2k/nativescript-urlhandler

Documentation is not enough the call back is never called.

scavezze opened this issue · 9 comments

I have followed the directions exactly. but the urlHandler never fires. I am running into this issue

NativeScript/NativeScript#3738

i have followed the directions above to cextend the native script activity but It precludes using your handler witch i really like because it helps pars the url and will work on ios. I tried adding

protected onNewIntent(intent: android.content.Intent): void {
	super.onNewIntent(intent) 
        this.setIntent(intent); 
}

instead of

protected onNewIntent(intent: android.content.Intent): void {
	super.onNewIntent(intent)
	if (intent.getDataString) {
		let data = intent.getDataString()
		if (data) {
			console.log('data', data)
		}
	}
}

This solves the issue and i can use your plugin without issue unfortunately this seems to break the ActionBar -> ActionItem click event i am not sure why

have you run into these issues using your plugin? am i missing something. I would really appreciate your help.

@scavezze you need to add android:launchMode="singleTask" to your activity in your AndroidManifest.xml. This will certainly resolve your issue. I've had to solve this exact problem before.

@scavezze Did I need to add the JavaProxy decorator and the extend?
Will try to add it to my plugin if needed

@roblav96 it's already set to single task

<activity
			android:name="com.tns.NativeScriptActivity"
			android:label="@string/title_activity_kimera"
			android:configChanges="keyboardHidden|orientation|screenSize"
			android:theme="@style/LaunchScreenTheme"
			android:launchMode="singleTask"
			android:exported="true" >

I noticed 2 changes were made tho one for the docs and one other one so let me get the latest and try it out

@hypery2k I think your really close i have tried whats currently avail and the following line throws a exception

application.android.init(this);

I think don't think you need that and the

protected onNewIntent(intent: android.content.Intent): void {
        super.onNewIntent(intent);
        if (intent.getDataString) {
            handleIntent(intent);
        }
    }

is called every time you receive a external link so i think you just need to remove that line then change handleIntent to something like this

export function handleIntent(intent: any) {
    let data = intent.getData();
    if (data !== lastReceivedData) {
        try {
            if (new String(intent.getAction()).valueOf() === new String(android.content.Intent.ACTION_VIEW).valueOf()) {
				getCallback()(extractAppURL(data));
				lastReceivedData = data;
            }
        } catch (e) {
            console.error('Unknown error during getting App URL data', e);
        }
    }
}

I modified my local version to what i recommended above and it works but again it stops the ActionBar -> ActionItem event from working. gonna try and figure that out .

ActionBar -> ActionItem event is not a issue with the linking. I think it's something with when i am changing routes in the handler

maybe you have to wrap it in a zone

@hypery2k

https://gist.github.com/scavezze/28d2e69aa39b69796769d729fc1ee638 with the 0.4.0 version of your plugin works also so i will leave it upto you if you want to change to use protected onNewIntent(intent: android.content.Intent): void { or jsut add it to your documentation.

I am new to Nativescript/Typescript so I will look into zones

@hypery2k , @roblav96
Thanks for your help i have it all working right now with the 0.4.0 version of your plugin