Android devices, ionic app and $cookies - android

I'm trying to create a little mobile app with ionic and a wordpress (and JSON API) for backend.
I choose cookie auth for log people. This méthode work perfectly in my web browser thanks but when I use "phonegap serve" or apk directly on my phone nothing happen.
According to following lines $cookies.put(...) seems not working on my Android device.
console.log("Cookie: ");
$cookies.put(data['cookie_name'],data['cookie']);
console.log($cookies.getAll());
Have you some idea to resolve my problem ?
Thank you

You can't use cookies, you should use localStorage.
To set the localstorage:
window.localStorage.setItem("key", "value");
To retrieve localstorage:
var value = window.localStorage.getItem("key");
To remove particular localstorage:
window.localStorage.removeItem("key");
To clear all localstorage:
window.localStorage.clear();
For your reference, you can use this link.
I am sure, this will help you.

Related

chrome devTools port forwarding: how to use session cookie domain?

I am developing a web app using different sub domains and I'd like to go mobile first so I thought using the chrome devTools would be wonderful.
My /etc/hosts file looks like that on my local machine:
127.0.0.51 account.example.local
127.0.0.52 web.example.local
The user need to authenticate on account.example.local and get redirected to web.example.local.
The problem here is that I had to set session_cookie_domain = '.example.local', so they can share the same session. Therefore, when I am using chrome devTools with port forwarding to test on my android device, I can't pass the login page because the device use localhost:5000 and I can't set session_cookie_domain = 'localhost' of course due to cookies specifications.
Question : Did anybody manage to make this kind of settings to work? Or is it simply impossible today ?
Thanks !
You can map to custom local domains, although I'll warn you, it may take some trial and error.

How can I get back to Google Sign In / Account Chooser in a Phonegap/Cordova app?

Building my first app with PhoneGap Build but cannot solve a problem which is, of course, an important piece.
The app uses Google oAuth2 to access an external site where I fetch data with Ajax. I use a url to do the initial login.
The only way I can get back to the Google Sign In is to delete and reinstall the app in iOS. In Android, I can use Application Manage and Clear Data.
In both cases, I get asked for the Sign In again as desired if I take either of those manual steps.
How can I programmatically clear the oAuth2 data which I believe is causing the problem?
Or, if necessary, what can I do to reinitialize the app entirely?
Thanks in advance for your suggestions.
Got this to work for me:
function googLogout (){
var ref = window.open('https://accounts.google.com/Logout?continue=http://google.com', '_blank', 'hidden=yes');
setTimeout(function(){ref.close();}, 3000);
alert('goog logout done');
}
Hope it helps someone else.

PhoneGap + Android + jQuery Mobile - Connection to server unsuccessful

I'm trying to create an Android (2.2) app using Phonegap (version 1.9.0) and jQuery Mobile (1.1.0). Specifically, the app is supposed to send a GET request to an existing WCF REST service and retrieve JSON data (a list of folders) and display each item as an option in a select drop down menu.
Right now, all this works as it should when I use the desktop browser. The WCF REST service sends the correct response, the browser renders the page correctly and puts the options in the select menu as I want it to. However, when I use the following code in Android app using Phonegap:
$.getJSON('http://xxx.xxx.xxx/MobileService.svc/GetFolders?callback=?', null, function (folders) {
$.each( folders, function( i, folder ) {
$("#folders").append("<option value='"+folder.Id+"'>"+folder.Name+"</option>");
});
$("#folders").selectmenu("refresh");
});
...I get the error message when I boot the Android app (debugging on physical device):
Connection to the server was unsuccessful. ("file:///android_asset/www/index.html")
When I comment out the above $.getJSON code, the app loads fine, but the select menu is unpopulated.
I've also noticed that apparently because Phonegap uses the "file://" protocol, it is not affected by the "same-origin policy" that the "http://" protocol is...I had been using JSONP when I was working with the browser, which is why I have the callback. I don't think this should be the reason why it is failing, but I dont know. Any help will be greatly appreciated!
Things I've tried:
Changing the access origin to ".*" in the cordova.xml
Adding 'super.setIntegerProperty("loadUrlTimeoutValue", 60000);' to the activity
You can try to set your cordova.xml to "*" instead of ".*" as seen on the Getting Started Guide
Or even better:
http://xxx.xxx.xxx
It turns out in my particular case that the issue boiled down to the mobile phone being on guest wifi network that didn't have access to the network where the REST service was hosted so the connection was being blocked.
Hope that can help someone

How to maintain session on a phonegap android app

I am new to phonegap development and currently developing an app that will run on android, i-phone and on windows phone. But getting problem in handling session from phonegap app - I got few post here on stack overflow but that was only for iphone using appDelegate.m defining cookie storage and also I got few post for only android storing session in HttpClient object coded in java - but is there anything on phonegap side to handle session - because then we can use the same code for all 3 devices ( iphone, android, windows ).
Probably I may sounds some sort of odd but I am really undecided as can't find any clue how to maintain the session and how to use the same session on consecutive calls to serverside script for gettinf different session specific information.
Is there any common way to achieve this that I may missed. Any help is highly appreciated. Thanks in advance.
With Regards,
Supriyo
Unless I misunderstood you, HTML5's localStorage is the way to go.
It is implemented in Phonegap, as described here: http://docs.phonegap.com/en/1.7.0/cordova_storage_storage.md.html#localStorage
This one works for me.
var CheckboxValue=$("#rememberme").is("checked");
if (CheckboxValue== true)
{
var username = $("#user").val();
var password = $("#pass").val();
window.localStorage.setItem("username", username);
window.localStorage.setItem("password", password);
}

Phonegap ChildBrowser Issue

I am creating a mobile app which connects to some jive based community using childbrowser.
I can easily open the community, login and do stuff.
But I also need to fetch session details in my app, so that I could use these to fetch JSON strings to show user image/info on my app showing that user is logged in.
I tried working on childbrowser, but couldn't investigate much.
It seems it won't work with my community URL. While using google url it shows popups on location changes, but not for my url.
Can any one help me in fetching the data I want ?
Here is the sample code I am using to detect location change:
function openURL() {
window.plugins.childBrowser.onLocationChange= function(loc){
alert('In index.html new loc = ' + loc);
};
window.plugins.childBrowser.showWebPage("https://communityName.jive-mobile.com/#jive-login", { showLocationBar: false });
}
I am getting my login page, but after login I can't see any alert coming !!
I need to get proof of user login and user session details.
Thanks
I have just updated the ChildBrowser plugin for my own use, following code given here: How do I get the web page contents from a WebView?
I am using this to log in on Google API oAuth2, watching for the right page to load. I am using the onPageLoaded(html) event that has the (computed) html source. You might want to use this to get the html that was loaded and check for "stuff". I don't use jive so I wouldn't know where to start, but I'll put up a sample Google oAuth2 project for you to try.
HTH
EDIT:
the code is at: https://code.google.com/p/filechunkreader/
Don't let yourself get fooled by the name, this project is the repo for my Java plugins experiments. It contains so far 2 plugins, FileChunkReader and a custom version of ChildBrowser.

Categories

Resources