phonegap android app only showing connecting to device - android

I AM creating a phonegap android app. I am creating this app using help of this tutorial. When i am istalling this app on device its onDeviceReady function is not working. It is only showing coneecting to device. My onDeviceReady function is below:-
onDeviceReady: function() {
app.receivedEvent('deviceready');
alert('device ready');
try {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"41327727848","ecb":"app.onNotificationGCM"});
} catch (ex) {
alert('error: ' + ex);
}
},
It does not alert anything. I can't find the error.

Here are the suggestions you can try:
make sure you have added cordova.js into your html file.
deviceready function should be called after cordova.js is loaded.
the link you've provided is using old version version of plugin.(link-old plugin).I advice you to follow the new one which is this

Related

Phonegap compass plugin not working

I am trying to get a compass function working on my app with no success. Judging by the errors I am inclined to think that the plugin is not being added or the device is not ready. But as far as I can tell I have done both things. I am using phonegap build, so the only code I use to include it is:
<gap:plugin name="org.apache.cordova.device-orientation" version="0.3.9" />
Which as far as I know is all that is required. When I click on the plugins tab in the phonegap build page for my app it shows up as being there.
watchDirection = null;
//Phonegap is ready
var whenDeviceReady = function(){
console.log("deviceready");
console.log(navigator.compass);
var findMyDirection = function(){
console.log("find my heading fired");
watchDirection = navigator.compass.watchHeading(
//onSuccess
function(heading){
console.log(heading);
var magnetDirection = heading.magneticHeading;
$("#movingCompass").css("transform", "rotate(" + magnetDirection + "deg)");
},
//onError
function(error){
console.log('code: ' + error.code +' message: ' + error.message);
},
//Update Frequency
{ frequency: 1000});
}
findMyDirection();
}
//Wait for phonegap to load
document.addEventListener("deviceready", whenDeviceReady, false);
The above code works as expected with the exception of the compass object. The console.log(navigator.compass); returns as undefined. And there is an error on the line which includes watchDirection = navigator.compass.watchHeading( saying Uncaught TypeError: Cannot read property 'watchHeading' of undefined.
It gets listed in the phonegap build list of installed plugins, and I already have the geolocation working with the same code format I have posted above.
#Marty.H, I have working demos here: http://codesnippets.altervista.org/examples/phonegap/demos/PUBLIC.Apps.html Go to the lower half of the page and try pre-built app, Phonegap-Compass-Test. If it works, the top half of the page has the links to github where you can get the source code. --Jesse

IntelXDK Android build issue with "Done" button

Good day! I am developing a simple mobile app using jQuery Mobile with InAppBrowser plugin on IntelXDK. The purpose of the InAppBrowser is to let users view external web pages within the app. On IntelXDK emulator, the browser closes when I click on "Return to App" button and then it returns to the app. However, I encountered a problem on an Android build when I clicked on the "Done" button I received the message:
Webpage not available
The webpage at file:///android_asset/www/[object%20Event] might be temporarily down...
I have used the following so users can click and view external web pages:
Opening links in external device browser with Cordova/jQuery-mobile
I have modified the above to be used on my app:
$(document).on('click', '.link', function (e) {
var elem = $(this);
var url = elem.attr('href');
if (url.indexOf('http://') !== -1) {
e.preventDefault();
document.addEventListener("deviceready", onDeviceReady, false);
onDeviceReady(url);
//return false;
}
});
function onDeviceReady(url) {
var ref = window.open(url, '_blank', 'location=yes');
}
Thank you for your time and help. I really appreciate it.
The reason why it was displaying an error message because the test file was calling another onDeviceReady function. Problem solved!

geolocation confirm box showing my index file url in phonegap ios application

I'm creating an ios app with phonegap 3.2 I need users current location to search nearby users. When i tried to get current location of device with code
function onSuccess(position) {
device_lat = position.coords.latitude;
device_long = position.coords.longitude;
}
// onError Callback receives a PositionError object
function onError(error) {
alert("Share Your Location First.");
}
function onDeviceReady()
{
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
A confirm box appearing with following text.
"/Users/../Library/Application Support/iPhone Simulators/6.1/Applications/[App Code here]/demo.app/www/index.html" Would Like To Use Your Current Location.
Is it possible to costomise this text as its say Like
"MyApp Would Like To Use Your Current Location" ?
Also for android and other devices.
I'm posting a new answer since the last one was incomplete. In order to get the geolocation prompt title to show your app name and not the full path to the file you'll need to do two things:
Install the Cordova / PhoneGap geoLocation pluin (cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git)
Run the getCurrentPosition after deviceready has been fired.
$(document).ready(function(){
$(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
});
I removed cordova geolocation plugin and everything working well. I'm using phonegap 3. navigator.geolocation.getCurrentPosition(onSuccess, onError); is also a html5 function so no need to other changes. Now it giving confirm box with message.
"MyApp Would Like To Use Your Current Location"
MyApp is the title of index page.

InAppBrowser events not firing in Cordova 3.0.0 / Android

Any suggestions on why I'm not getting events?
I'm opening the browser after deviceready:
document.addEventListener('deviceready', app.login, false);
I register the event listener, the login function below is called as expected, the foobar page opens, but I never get the "loadstart" (or any other) callbacks that I register for:
login: function () {
console.log("login");
var authorize_url = "foobar";
var appInBrowser = window.open(authorize_url, '_blank', 'location=yes');
appInBrowser.addEventListener('loadstart', function(event) { console.log('loadstart'); });
}
As far as I can tell I'm following the Cordova docs example. Thanks.
Solution: Don't forget to manually install the plugin. Without the plug-in the browser will still show up, but events won't fire:
Use the command line interface:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

device.uuid undefined in PhoneGap on Android?

I'm writing a PhoneGap application that sends requests to a central database. It needs to be able to identify the unique devices that connect to it.
PhoneGap's device.uuid property would seem to do the trick. On webOS and iPhone, I get back a unique string of alphanumeric characters, which will satisfy my need. However, the Android devices I've tested (Motorola Droid and the Android SDK emulator, both running Android 2.1) return "undefined" as the device.uuid.
device.platform and device.name return correct values on all three platforms, so the problem doesn't have to do with the device object itself (it's defined in the code blocks where I use it).
Is this an Android limitation? A problem with PhoneGap?
Is there any other way to get such a globally unique identifier if not through device.uuid?
EDIT: It appears that the deviceready event is never getting fired, which needs to happen before the device.uuid property becomes available.
Depending on Phonegap version and/or device, you might need to install the plugin explicitly. In our project, device was present but device.uuid was undefined. Running cordova plugin add org.apache.cordova.device fixed the issue in our case.
I haven't yet found a solution for this, but it is worth noting that this issue is fixed in Android 2.2. But other than that, you'll have to find some other way of getting a unique device identifier if the device is running 2.1 or earlier.
I had the same problem. It was working previously, and I eventually traced the problem back to the manifest permissions.
If android.permission.ACCESS_NETWORK_STATE is not enabled, deviceready will not fire, and device.uuid will not be available.
this works for me:
first installation of device plugin:
cordova plugin add cordova-plugin-device
and in my index.js i have this:
var app = {
initialize: function() {
$.support.cors = true;
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
receivedEvent: function(id) {
console.log('Received Event: ' + id);
},
getDeviceInfo: function() {
var aio = new Object();
aio.agent = device.platform + "," + device.version + "," + device.model;
aio.deviceid = device.uuid;
return aio;
}
};
app.initialize();
module.controller('AppController',function($scope) {
console.log('GOOOO');
ons.ready(function() {
console.log("ons ready");
var appInfoObj = app.getDeviceInfo();
console.log("Agent: " + appInfoObj.agent);
console.log("UUID: " + appInfoObj.deviceid);
});
});

Categories

Resources