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
Related
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
I'm using Phonegap EMailComposer plugin with Android to send a file attached but when the mail client (gmail app) opens I always get the same error "the file can't be attached'.
This is the code I'm using:
cordova.plugins.email.open({
to: 'XX',
subject: 'XX',
body: 'XX',
attachments: '//file.csv'
});
I'm quite sure the path is right becasuse when I use any other file path the error changes into "attached file can't be empty'.
I'm using cordova CLI 4.0.0 and plugin version is 0.8.2. I've tested it in Android 4.4.2 and 4.2.1
Any idea?
According to the documentation you need to use
attachments: 'file:///storage/sdcard/icon.png', //=> Android
but that didn't work for me so I tried without storage and it works for me. (I'm using Android 5.1.1 for my tests, so i don't know if it works in your case for Android 4.x)
Try with:
attachments: 'file:///sdcard/file.csv
Does anyone know how to display local images, packaged inside a Cordova container, using Ionic (http://ionicframework.com/docs/)?
I am currently getting this error when the app runs on a device:
GET unsafe:local:///img/thumbs/myImage.jpg Unhandled Protocol
My Cordova app is built for BlackBerry 10 & Android using ionic framework. The app displays an image that is packaged inside the Cordova app itselfusing the following template:
<img ng-src="img/thumbs/{{img.path}}" ng-click="fooBar(img)"/>
Why is this error occurring?
I've discovered this is a current limitation of the ionic framework regarding BlackBerry 10 support. I've logged a bug here: http://github.com/driftyco/ionic/issues/1066
To fix this, I've since manually edited the ionic library to include support for the local protocol.
Angular issue
Replace following lines in ionic.bundle.js
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob):|data:image\/)/;
to
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file|local):/,
imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob|local):|data:image\/)/;
I've just pull request to Angular, because it's an Angular limitation, not of the Ionic framework. You can see the pull-request here: https://github.com/angular/angular.js/pull/8787
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.
I am trying to build a cross-platform application for Android and iOS and have chosen to use Boost to simplify communication and to parse the JSON from the response. Everything works fine in iOS, but Android fails with "service not found" error, or "host not found (authoritative)" if I change the query to query(server, "");.
I pulled the code out of my application and simplified it to what was throwing the error and this is what I have:
...
#include <boost/asio.hpp>
boost::asio::io_service io_service;
std::string server = "<server_address>";
// Get a list of endpoints corresponding to the server name.
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(server, "http");
boost::system::error_code ec;
boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query,ec);
if (ec)
{
return env->NewStringUTF(ec.message().c_str());
}
I am using Android NDK r8e (64-bit) and Boost version 1.53 (latest releases as of writing). I have used https://github.com/MysticTreeGames/Boost-for-Android with slight modification to work with the 64-bit NDK (see https://github.com/MysticTreeGames/Boost-for-Android/pull/28) for building the required Boost libraries.
I will be modifying this to work with async_resolve, which is what the iOS version is using, once I can get this part working.
Edit:
I noticed I had forgotten to update the Android Manifest file, so I added
<uses-permission android:name="android.permission.INTERNET"></uses-permission>, but I still get the same errors. Am I simply missing something else in the manifest?
It means that the OS can't figure out which port stands for http. On most POSIX-compliant systems this mapping is done in /etc/services file, and if http line is missing there, you'll get "service not found" error.
I don't know whether Android has this file or not (older versions didn't support it at all, the services were hardcoded in bionic), but if you get the above error, the only workaround is to set the desired port manually:
tcp::resolver::query query(tcp::v4(), yourHost, "80");