dpa99c / phonegap-launch-navigator

Phonegap/Cordova plugin which launches native route navigation apps for Android, iOS and Windows
369 stars 131 forks source link

support option to remember selected app #88

Closed pke closed 7 years ago

pke commented 8 years ago

Native app pickers usually have an option to launch the app only once or always use the same app from now on. Would it be difficult to add such feature?

dpa99c commented 8 years ago

Native pickers usually have a 2-state toggle such as checkbox to indicate if the user wishes to remember the selection. This plugin (currently) uses cordova-plugin-actionsheet to display the list of available apps. And since actionsheet itself uses native UI elements, I don't see any easy way to add a checkbox to that UI without either forking the actionsheet plugin or swapping it out for a different UI widget. So it doesn't look like something I can add easily/quickly.

In the meantime, the plugin API is sufficient that you could create your own UI which incorporate a "remember" checkbox and persistently store the user choice (e.g. in local storage).

pke commented 8 years ago

And there is no way to display the native picker like the social sharing plugin does?

dpa99c commented 8 years ago

I didn't say there's no way to do it: there's probably another UI element that Actionsheet can be swapped out for. But it's not trivial and I don't have much time right now.

jvjvjv commented 8 years ago

I do have an idea, @dpa99c. While this will not specifically cover @pke's request, you can return the app used in the success callback, and then @pke can save it in his app, and going forward, specify that app as the default.

Also, pke could create a settings view within his app where the end user can select or change their default navigation app using methods you've already provided us, regardless of the above implementation.

MichalFoksa commented 8 years ago

+1 for @jvjvjv idea. Please return selected app in the success callback.

pke commented 8 years ago

I just wonder: When I use a mailto protocol link Android displays a "choose once" or "choose always" for the mail app. Is that a standard system dialog or not? I know in Windows Phone there is such dialog (at least it was until the hideous Windows 10).

Otherwise I'd be happy with the solution @jvjvjv was suggesting.

dpa99c commented 8 years ago

Yes, it's a system dialog which is hard-coded in the operating system for specific protocols. For example, mailto: and, more relevantly, geo: protocol. Making a URL call to the system browser using one of these protocols, it is intercepted by the operating system. On Android, this triggers the picker dialog which includes the "choose once" or "choose always" behaviour. However, these are a limited number of hard-coded protocols that the OS invokes special behaviour for. The default behaviour of this plugin (if an app is not specified) is to present a list of available apps to the user. However, the native system dialog behaviour for these specific protocols cannot be leveraged for this purpose: we have no means of defining a new special protocol which will be intercepted and understood if opened in the system browser.

@jvjvjv has made good compromise solution and I'll implement it when a get some time.

pke commented 8 years ago

@dpa99c I see. I tried the geo protocol before. Unfortunately not all navapps register themselves for this protocol. So even when I have gmaps installed on iOS it will still always launch Apple maps. That's why I even considered using this plugin. Usually I go with system protocols to launch apps.

dpa99c commented 8 years ago

Just published v3.2.1 to npm. Using that version, you should be able to specify appSelectionCallback option which will be passed the app that was selected by the user in the native picker.

dpa99c commented 7 years ago

@pke Happy with the appSelectionCallback solution? Can this be closed?

pke commented 7 years ago

Yes, I'll see what I can do with it

dpa99c commented 7 years ago

FYI v4 of the plugin (just published) now supports a mechanism to remember which app was selected. By default, it uses cordova-plugin-dialogs to ask the user whether to remember the selected app on the first time they are shown the available list of apps. However, this behaviour can be customised with a custom UI using promptFn option: see the updated docs for details.