I am trying to bind a call to 'backbutton' event that is supposed to be called when a cordova app is run on an android device and the user hits the back button.
http://cordova.apache.org/docs/en/3.0.0/cordova_events_events.md.html#backbutton
I cannot seem to get this event to fire.
This google groups post references that the App plugin has been removed and doesn't seem to provide any solution, just wait for cordova 3.1.
https://groups.google.com/forum/#!topic/phonegap/qgo-HdW4C_g
According to the post in google groups the device api has not included in js file. So you need to wait for the next release.
This link may help you to use customize plugin to handle back button in android.
Send Application to background mode when back button is pressed in Phonegap
Related
We want to be able to send a notification to the device when our app is terminated on user's device (not paused).
On iOS this is when you double click the home button and swipe up on the app, and Android this happens then you press the Menu button and swipe the app to the right.
In Cordova, there are the following events:
deviceready
pause
resume
backbutton
menubutton
searchbutton
startcallbutton
endcallbutton
volumedownbutton
volumeupbutton
activated
None of these events will fire when the app is terminated. The closest event is pause, this is fired when the app is terminated, but also when the app is moved into the background, and there isn't a way to tell which one is happening. Plus any processes that need to happen will only happen when the app is un-paused later.
My question is, how can my server know (or be notified) when you have terminated the app, in a reliable way. In order for me to be able to send a push notification.
This is not possible on iOS; the operating system may signal in advance with a low memory warning, but that doesn't mean the app will be terminated.
On Android, Cordova does not offer any support natively for this. You might be able to accomplish something with plugins and the information here: How to handle code when app is killed by swiping in android?
I am working on a cordova app that makes use of the accelerator data. But I need the app to be aware of acceleration originating due to phone vibration, in order to account for it.
I understand that there exists support to create vibrations in HTML5 via the vibration API, but is there a way to fire/listen to events corresponding to vibration triggered by some other application or the OS?
You can check out the cordova accelerometer plugin (cordova-plugin-device-motion). you can add it to your cordova mobile project using
cordova plugin add cordova-plugin-device-motion
You can find out more from [here]: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device-motion/
I made an app using PhoneGap that needs to access the user's current latitude and longitude to function.
Here's what I did:
navigator.geolocation.getCurrentPosition(function(pos) {
// code using pos
});
On the browser this asks your permission to access the info, but on the finished app it doesn't ask anything and just doesn't work.
Is there anything I'm doing wrong/missing?
#Dogmatics,
there is not enough information to debug your problem. Assuming you turned on the GPS and Location services, then you forgot to wait for the 'deviceready' event.
From the documentation:
This is a very important event that every Cordova application should use.
Cordova consists of two code bases: native and JavaScript. While the native code is loading, a custom loading image is displayed. However, JavaScript is only loaded once the DOM loads. This means your web application could, potentially, call a Cordova JavaScript function before it is loaded.
The Cordova deviceready event fires once Cordova has fully loaded. After the device has fired, you can safely make calls to Cordova function.
If this proves to be correct, you will want to read #4 in:
Top Mistakes by Developers new to Cordova/Phonegap
https://github.com/jessemonroy650/top-phonegap-mistakes/blob/master/new-to-Phonegap.md
Best of Luck
I created a PhoneGap app for iPhone that uses geolocation via JavaScript inside webview.
When I run the app the first time, it'll prompt me to allow geolocation for this app.
When I hit "ok", it'll prompt me again with the same question but this time it states that "index.html" wants permission to use geolocation.
That makes sense because iOS probably wants permission to allow geolocation for the app itself for the first time and the 2nd time the browser wants permission.
However, since doesn't lead to a great user experience:
How can I prevent this double prompt? (I'd be enough if the 2nd prompt could be prevented)
I found the cause for the issue.
The call to navigator.geolocation.getCurrentPosition(onsuccess, onerror) happens before Phonegap was fully loaded.
This means that the geolocation call of webview (and not a native call via PhoneGap) is being triggered which will again ask for permission (which does make sense). Compare it to the normal Safari browser on your Smartphone. It'll ask for geolocation permission for every new website. It's the same when loading index.html via PhoneGap on application startup.
However, the solution is to wait for the deviceready event which gets fired when PhoneGap has fully loaded:
document.addEventListener("deviceready", function(){
navigator.geolocation.getCurrentPosition(onsuccess, onerror, params);
}, false);
This will make the PhoneGap API available which overwrites the default HTML5 gelocation call of the browser and get the device's geo location via a native call (which you already accepted in the first prompt).
This will work because PhoneGap's API calls are identical to the standard W3C call for HTML5: http://docs.phonegap.com/en/2.2.0/cordova_geolocation_geolocation.md.html#Geolocation
Have a look at this:
Location permission alert on iPhone with PhoneGap
The second one seems to be the Webkit alert. In order to prevent this, you seem to have to simply move all your js files to the root directory. Tell me, if it works since I'll have to address the same issue soon.
Finally fixed the issue.
IN the index.html just move your cordova.js up
<script src="cordova.js"></script>
as the first js file to be included (especially make sure it is above maps include js). This will make sure that the prompt shows only once
I solved this problem by moving the
<script src="cordova.js"></script>
as the last script to be included
Ok here is my problem, I've inherited an old ASP.NET 2 website which I've been asked to make iOS capable. My biggest headache so far is that because of the way you have to log into the system right now I need to pass the UserName to the iphone and also run the server Click event. I can do one or the other but not both, and hooking up to the username textbox via either the KeyUp event or the OnChanged event causes other problems with the Objective-C code for the iPhone.
Is there anyway that I can update both the phone and the server at basically the same time?