Android: Phonegap 3.1.x fail to load geolocation plugin - android

We are using Phonegap 3.1.0-0.15.0 and the application chocked when trying to access location information.
Works fine in iOS however the App chock on Android
We are using:
navigator.geolocation.getCurrentPosition(app.location.onSuccess, app.location.onError);
and we also tried:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(app.location.onSuccess, app.location.onError);
The logcat mentioned the following:
Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1511
Uncaught module cordova/plugin/geolocation not found at file:///android_asset/www/phonegap.js:56
The plugin was added using:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Are we doing something wrong ?
Thank you in advance
/Edwardo.

Just to answer my own questions. I removed all the plugins manually and then add them (including the problematic geolocation plugin) using the following command:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
That solved my issue.
Edward.

Related

Cordova: cordova_plugins.js failed to load resource

I am learning to use cordova and i have been just doing a normal install of android platform in my cordova application, everything worked fine except for some errors i don't intent to fix just yet (which are external resource files loaded from javascript). I just installed phonegap-plugin-push for working on a push notification support, i believe i have to first register the device on which the notification should be recieved so i ran the app without any other configuration rather than downloading the libraries and putting the google-services.json file at the root application folder.
I try to find the commands for pushing but i am unabled to do so and i think it might be because of an error thrown in the console
Failed to load resource: net::ERR_FILE_NOT_FOUND /cordova_plugins.js
so i have been searching on google and i have found that i don't need to add anything but cordova.js as i have already done upon cordova application installation in order to work with cordova features.
I don't know if i have to add something else or if i am missing some code in order to make this plugin work, probably this plugin is not compatible with cordova but phonegap is built over cordova so i don't know.
in case it is necessary, this are the versions i am using:
Cordova-CLI: 7.1.0
Google Play Services: 46
Android support repository: 47
Android SDK: 26
I failed to say that the application running in cordova is done with angular and angular-ui-router.
After long hours of testing i've found out that the problem is caused by angular-ui-router, because i was using angular-ui-router i have set a <base href> tag in the head tag which is what is making cordova to fail, this is now actually how cordova is intended to work, it is because of how the files are placed. On android the files are placed in android_asset/www/, i don't know how the files are placed in other platforms, but when <base href> tag is set with a new value then the calls are now trying to be done in a directory where the files are not placed.
The solution in angular is to not set a <base href> tag and disable html5Mode in the config
app.config(["$stateProvider", "$locationProvider", "$urlRouterProvider",
function($stateProvider, $locationProvider, $urlRouterProvider){
// Set the default url state
// NOTE: Do not set <base href> tag, this breaks cordova calls
$urlRouterProvider.otherwise("/");
// Disable html5 native router mode
$locationProvider.html5Mode(false);
......
}
]);
I've realized this because in chrome device remote inspector i was getting error calls to wrong directories, by looking at the url where the application is running i saw that the calls were not in the proper directory

push notification using Onesignal error

while trying to create a push Notification using GCM Per device or a group of devices - we are trying to use Onesignal for registration of our android users and getting an undefined error.
the code is written on JS and then build using Phonegap and realesed as an APK for android, while debugging it we get "windwos.onesignal undefined"
any lead or help would be appriciated
Thank you
(can't post the Chrome debugger message rep 10 is requered :-) )
Is windwos.onesignal exactly what you have in your code? Or is this a typo in your post?
All calls to OneSignal should be called by with window.plugins.OneSignal.
Example:
window.plugins.OneSignal.sendTag("key1", "value1");
Check to make sure window.plugins is defined where you're calling OneSignal. It should be called from your onDeviceReady function or add a 'deviceready' listener if you don't have this function. Double check your code with OneSignal's Cordova/PhoneGap install instructions.
You can also send your APK to support#onesignal.com and we can help debug your issue.
Follow the documentation here Make sure you add plugin
> cordova plugin add onesignal-cordova-plugin
And try building it locally.
>ionic build android
If it works locally there is some issue with you config file.Specify version of plugin in config file. Check your installed plugin version.
<plugin name="com.onesignal.plugins.onesignal" spec="1.9.0" source="pgb" />
Hope this helps !

how to use clipboard plugin with a phonegap build app

Has anyone gotten the clipboard plugin to work with "PhoneGap Build"?
I can't get it to work. I'm currently useing phonegap 3.1.0
My app is for android and IOS. I've only tested the clipboard plugin on android so far, and it isn't working.
in my config.xml:
<gap:plugin name="com.verso.cordova.clipboard" />
in my javascript:
window.plugins.clipboard.copy('some text',function(){alert('success');},function(response){alert('error:' + response);});
window.plugins.clipboard.paste(function(text){alert('paste success:' + text);},function(response){alert('paste error:' + response);});
The way I have it above, the script runs, but for both the copy and paste calls, the error function is executed and the response is "Class not found".
I have tried the above call window.plugins.copy, cordova.plugins.copy
both of those just cause the script to abort.
phonegap is loading just fine and the deviceready function has already fired before I attempt the above calls.
Under the plugins tab on the phonegap build webpage for my app:
Installed 3rd Party Plugins
com.verso.cordova.clipboard 0.1.0
This appears to be unrelated to the copy/paste plugin. In phonegap 3.1 you have to reference all the phonegap plugins you want to use. In this case, I'm guessing you have a function that checks if the user has an internet connection? If so, you need to add to your config.xml

Pusher not working on Phonegap for Android

I'm facing a problem and would really appreciate your help...
Android SDK: 4.0
Phonegap: 1.8.1
Pusher: 1.12
I have created an Android project using Phonegap that needs to receive server notifications through Pusher.
I'm running it in Eclipse and AVD emulator, but the problem is that every time I try to establish a connection to pusher, I get an Unavailable state from the bind to state_change.
I have tested the connection to Internet in the emulator browser and it works fine. I have also tested that the server is responding and that the Pusher key is the right one by testing my code on Firefox.
This are the steps I have followed:
I have included the WebSocket.java and WebSocketFactory.java files in the src folder.
I have included websocket.js file in my js folder and included a reference in the index.html file.
I have included a reference to http://js.pusher.com/1.12/pusher.js in the index file.
I have included the following line in my Android App.java file: this.appView.addJavascriptInterface(new WebSocketFactory(this), "WebSocketFactory");
This is the code I'm using to connect to Pusher:
// Connect
var pusher = new Pusher(CONFIG.PUSHER.APP_KEY);
pusher.connection.bind('state_change', connectionStateChange);
function connectionStateChange(state) {
alert(state.current);
}
Is there something I'm missing? Any ideas on why the connection is not working or about where to check?
Thanks for your help.
Chadid
For version 2.x of pusher-js and above the library will work within PhoneGap without any additional requirements or setup. Simply include the library and use it - no need for WebSocket.java or WebSocketFactory.java.
For version 1.x this blog post and associated code demonstrates how to get Pusher working on PhoneGap:
http://blog.pusher.com/2012/7/5/pusher-on-phonegap-for-android

window.plugins undefined when trying to use the phonegap plugins on android

I can't load the plugins in android. I have added the plugin to the plugins.xml list, have added the java code in my project. But still when I call window.plugins I get undefined object. Why is this happening? BTW I'm trying to use the share plugin - https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share
Just to be clear, I have added the phonegap.js file and the share.js file containing the JS plugin code. Also I have used the EmailComposer plugin for iphone with same code and it works on iphone, i.e. on iphone the window.plugins object it isn't undefined.
I fixed the exact same issue after noticing... i forgot to reference phonegap-1.1.0.js in my html. I also had to uncomment PhoneGap.addPlugin('share', new Share()); in share.js.
I had the same issue and I think I found the problem with phonegap.
You should go see on this thread, it may explain why you can't access your plugins : Phonegap background geolocation plugin not found
In phonegap 1.1.0 we can't call the windows.plugin what we need to in your share.js instead of
PhoneGap.addConstructor(function() {
});
add navigator.your plugins.js=new WebIntent(); (Java file) and call the plugin as navigator.your javascript plugin name in your javascript.

Categories

Resources