I am developing a phonegap application using phonegap build (therefore ALL in pure js and html, no native languages).
In my page, i have some geo uri links (http://en.wikipedia.org/wiki/Geo_URI ) that are cliccable (they represent coordinates of markers in a map).
Now, if the mobile device has installed and associated with this type of files an app (usually a gps navigator or the like), they open and launch the associated application as they should.
My issue is that I don't want to show the clickable link (the button appears in the infowdindow of the marker) if the device has no app capable to open them.
In native android code, you have the query-intent command for this. Does anyone know how to verify this in pure phonegap js?
Ty!
D.
I have been asked for code: The only code that is relevant here is the following, which computes the html code to embed in the infowindow of the marker:
var computePathString=<a href='geo:"+area['marker']['position'].lat()+",
"+area['marker']['position'].lng()+"'>Route</a>;
Which translates to the following html:
<a href='geo:45.557,9.1523'>Route</a>
Which works great on click IFF the device has an associated app (usually a gps navigator), but else does nothing on click. I need to achieve something similar to the query intents of android:
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
only, in native phonegap js.
Related
I have a web application that needs to open a destination in the native maps/navigation app on the device. On most Android devices this is google maps, and I can simply open a link that will open google maps with the directions to the passed destination (latitude, longitude coordinates). In the case of the TomTom Pro 8375, there seems to be no way of opening a destination in the navigator app from the browser.
We have tried this, amongst others, with the following:
tomtomgo://x-callback-url/navigate?destination=52.371183,4.892504
tomtomhome://geo:action=navigateto&lat=mylat&long=mylon&name=myname
Are there any known workarounds to achieve this?
I have received this as a response from the support but this applies only for kotlin or java.
Uri gmmIntentUri = Uri.parse("google.navigation:q=52.0000,12.0000");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent)
Is there a way that I can make this work in Javascript ?
I would really appreciate any suggestions!
Thank you!
Too Long to be a comment
Not overly familiar with webapps however we do have 3 apps with Webfleet. Sadly we use Java not Javascript. And the intent we use is
String uri = "geo:0,0?q=" + <destination>;
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));
Not overly helpful for you however we must support both phones and the Pro tablets.
The format below is the standard for JavaScript ?
intent:
HOST/URI-path // Optional host
#Intent;
package=[string];
action=[string];
category=[string];
component=[string];
scheme=[string];
end;
Which i would give you a rough estimate of:
intent://#Intent;action=android.intent.action.PICK;type=text/plain;S.android.intent.extra.TEXT=geo:0,0?q=52.0000,12.0000;end
I will also add the App that is Webfleets version of maps is called NavPadNavAppActivity, can try targeting that directly?
I have an android app with a WebView, it is written in Java Script and Angular JS code to access the Camera , I just load the URL in web view and had given camera access permission and read and write external storage permission, still it is not able to access the camera , I had browsed for this problem ,but didn't find the exact solution.
I just want to open the camera , when user click on take photo on his profile page which was written in java script code , don't know when this will happen because I have base URL only which was loaded in web view.
How to let the user open the camera in this application? And also it should support from Kitkat onward, Can any one help me to figure out this?
Use openChooser method when implement UIClient
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.addCategory(Intent.ACTION_CAMERA_BUTTON);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i,"File Chooser"), 111);
}
We have a web based jquery mobile app that records activity of a user. This app is long standing and in use at the moment, so re-writing the application is not an option unfortunatly.
The problem is that we are trying to get GPS location at certain points using the application.. But as it is running in an instance of chrome, the javascript will not record correctly when the phone is locked, or the chrome is minimised.
So to get around that we are writing an Ionic App with Cordova in order to get the GPS coordinates in the background, regardless of the state of the browser.
Currently, this is working great. The issue however is there are certain events in our javascript that require a specific 'type' associated to our GPS logging.
My question is: How do I actually hook onto this javascript event in CHROME from the GPS background ionic/cordova application.
What we have tried so far:
Finding the chrome localstorage via Ionic/Cordova and reading a value from that on a timer.
The issue with this is we can't find the location of the localstorage/cache.
From this question it says its here:
/data/data/com.android.chrome/cache
but we can't find/access it from our ionic app or file browser on the android
https://android.stackexchange.com/questions/85998/android-google-chrome-browser-cache-location
We have also looked for ways to hook the javascript events to fire something inside the other application but we are having no luck there either..
Apologies for the long post.. Its hard to explain. If you have any suggestions on alternative methods to do this kind of cross-application event firing from Chrome to Ionic/Cordova I would be greatly interested to hear your oppinion.
To fix this I created a 'stack' where I could push an object to an array that would be picked up by the cordova app using executeScript as follows:
In the inappbrowser site:
var stackName = stackN1
function addEventToStack(numid, type) {
var stackRow = { 'numb': numid, 'type': type};
var stack = localGet(stackName); //localstorage
if (!stack)
stack = StackInit();
stack.push(stackRow);
localStore(stackName, stack);
console.log('Added to stack ', stack);
return 'Row Added';
}
In the cordova application:
ref.executeScript(
{
code: 'localStorage.getItem("stackN1")'
},
function(rdObj) {
//Iterate and use rdObj here
}
here's my situation. I have a html +css + jquery well working project that I want to adapt in titanium. This project has geolocation + fb api call.
I want to adapt my project into a titanium html5 project. What I found is that I can call titanium api only through addEventListener and fireEvent functions (of course only if I use webviews).
it' my first titanium project I work with that needs geolocation and facebook api.
actually, I started to modify the previous project by adding addEventlistener into the app.js file and fireEvents into the javascript files of the previous project ( included in the first project in the html files) in the parts that need the titanium api calls (I can't call titanium api outside of app.js).
the problem is that I need some values (objects) to be returned back.
to better understand what I'm doing, here's the sequence of the events.
TITANIUM PROJECT
(app.js)
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'index.html'
});
Ti.App.addEventListener('geolocation',function(){
//some titanium api call
lat = x;lon=y;
Ti.App.fireEvent('geolocation_back',{latitude:lat,longitude:lon});
});
win.add(webview);
win.open();
HTML + CSS + JS PROJECT
(imported file into index.html, not imported into app.js)
Ti.App.fireEvent('geolocation');
var my_lat ;
var my_lon ;
Ti.App.addEventListener('geolocation_back',function(d){
my_lat = d.latitude;
my_lon = d.longitude;
//do other stuff with my_lat and my_lon
});
I hope you understand what I'm doing.
my questions are:
1) is what I am doing the correct way to work with titanium and html code?
2) is there anyother way to call titanium api within html code and return variables/objects back?
EDIT
this code works only on iOS and android but not on web browser. it seems that the built in server (Titanium studio or Android web browser emulator) doesn't load the Ti.* or Titanium.* objects. is there anyway to make it works on web browser?
I see the web mobile compiler creates all the titanium API in subfolders
there is titanium.js and TI/* folder. can anyone explains me why the console says me Ti is not defined?
as I said here
I found a solution!
simply add to all of your html pages the simple script below
var Ti = window.parent.Ti
have fun!
I have two variables - Destination and Source - and, using Phonegap, I'm trying to use jQuery to open the external iPhone Apple Maps app with directions.
The code I'm using looks like this:
var url = 'http://maps.apple.com/?q=daddr='+destination+'&saddr='+source;
window.location = url;
Whenever I click the relevant button however, it opens a new view in-app with Google directions as a webview, and I cannot return to the original app.
How can link be opened instead with the iOS default map application?
Changing http://maps.apple.com/?q= to just maps: did the trick.
NB: make sure you write maps: and not map: as, while the latter will run the correct app, it will crash immediately after opening (thanks jprofitt)
Today I was able to open the native Apple Maps app with marker from a Cordova app using BOTH of the follow URL schemes:
maps://maps.apple.com/?q={latitude},{longitude}
AND
maps://?q={latitude},{longitude}
In a link:
<a href="maps://maps.apple.com?q={latitude},{longitude}">
<!-- OR -->
<a href="maps://?q={latitude},{longitude}">
From JavaScript:
window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;
// OR
window.location.href = "maps://?q="+lat+","+lng;
The app is running on an iOS device, iOS version 8.1.2, and cordova-ios is version 3.7.0.
In my case, changing from http://maps.apple.com/?q= to only maps:?q= not solving the problem.
The working scheme that open native Apple Maps with marker is as follows:
maps://maps.apple.com/?q={latitude},{longitude}
full working code:
window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;
Tested working with iOS7.1 simulator, might not works in later version. I don't have the opportunity to test. Sorry.
Supported Apple Maps parameters can be found here:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
Credit goes to this SO link: Here
The code
I managed to get this working in 2018 on iOS 11.2 using the following format in iOS:
<a onclick="window.open('maps://?q=51.178847,-1.826160', '_system');">Open in Maps</a>
And this format on Android:
<a onclick="window.open('geo:0,0?q=51.178847,-1.826160', '_system');">Open in Maps</a>
Config permissions
Additionally, don't forget to add permissions to your config.xml file like so:
<allow-intent href="maps:*" />
In my project the geo: intention had existed from the beginning so it took my a while to figure out why this was working on Android and not iOS.