Cordova OverrideUserAgent preference not working - android

I'm building hybrid mobile apps using cordova and quasar framework.
I used the following user agent to change the default user agent.
<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
in config.xml for both ios and android preferences
its working fine for iOS but
not working for android (giving null value in OverrideUserAgent preference in generated code)
cordova-lib#9.0.1
platforms list :
android#8.1.0 and ios#4.5.5
How do i make it work for android ?

Have you tried using AppendUserAgent instead?
If set, the value will replace the old UserAgent of webview. It is
helpful to identify the request from app/browser when requesting
remote pages. Use with caution, this may causes compitiable issue with
web servers. For most cases, use AppendUserAgent instead.

Related

Phonegap / Cordova / jquery not connecting Internet

I have a small app to test:
https://github.com/vmbelizario/phonegap
its just a login form who connects to a PHP page and check if the login exist.
The side-server is the auth.php file.
The client-side is the js/auth.js who connect to http://myserver.com/auth.php (example) and do the login test.
If i upload in a apache + mysql server, works.
But in android, after put the credentials i got only "connecting..." and didnt worked.
I tested via adobe builder (build.phonegap.com/apps) build and install in my smartphone and via monaca.io android emulator.
Can someone check what is wrong and help me?
Thanks!
Make sure you have the Cordova Whitelist plugin installed.
cordova plugin add cordova-plugin-whitelist
This is required for Android and not on iOS or Browser.
Then check your config.xml for lines like these.
<access origin="*"/>
This will allow any network communication from your app. To be more safe you can change this to.
<access origin="YOUR_URL/*" />
This will allow network access only the the URL specified and any subdomains.
See the documentation here.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
I think you need to use the query string in the url. Try to concatenate the URL with your data string and pass it as a complete url in your ajax call. First try to hit the complete URL with static values in the browser, if it works then that's a solution for your problem. For example: http://myserver.com/auth.php?callback=?email=example#mail.com&password=password&login=

Android devices, ionic app and $cookies

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.

Sencha Touch 2.1 native (android) app not getting json from remote (it works on PC)

I created my first Sencha touch 2 app by watching this video (http://youtu.be/5F7Gx0-W-M4) and it has a store page structured like this:
Ext.define('FirstApp.store.Places',{
extend:'Ext.data.Store',
config:{
autoLoad:true,
model:'FirstApp.model.Place',
proxy:{
type:'ajax',
url:'https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyCFWZSKDslql5GZR0OJlVcgoQJP1UKgZ5U',
reader:{
type:'json',
rootProperty:'results'
}
}
}
})
The after-build (after running "sencha app build native") package work very well on my MAC (all browsers) but the generated app (i am running it on my nexus phone) works but doesn't collect any data from the google maps json.
Any help would be appreciated
The example you are referring is using google map's place search API. You can not use this API when you build the app for mobile phone with proxy set to ajax . Basically, you can not use any resource that is outside your domain. Like if your site is at yourdomain.com and there is someotherdomain.com, then you can't make ajax request to this someotherdomain.com from yourdomain.com unless that domain allows you to. In this case, your mobile app is not having any domain. You are just loading a page inside webview.
The reason is, ajax will not be able to load cross-origin resources. App build works on browsers because I believe you're using chrome with --disable-web-security flag. To work with CORS you need to use JsonP proxy. It's the only way if you're packaging for mobile app. If in a case, you own the server ( not in this context though ) then you can allow CORS by setting appropriate headers like
Access-Control-Allow-Origin: *
or
Access-Control-Allow-Origin: http://yourdomain.com/resource
Try setting proxy to JsonP .

PhoneGap Build for windows phone and other platforms

I have started a project in phonegap for windows phone, and created a login form. Backend I have written some c# code for perform some api methods and check login.
And I have build the phonegap and got output file for all the platform. Whether is it compatible with all other platform than windows ?
I'm afraid your c# code will not be compatible with other platforms. You either need to write Phonegap plugins for each platform or write JavaScript to check login.
Depending on your situation, Phonegap has APIs for accessing the device's filesystem or making use of browser storage (Web SQL database).
See the Phonegap API for more info
For working with cross platform, I have created a web service and called the method of web service with ajax call,
If the webservice hosted in any other domain you should use
$.mobile.allowCrossDomainPages = true;
$.support.cors = true;
Refer more :- http://jquerymobile.com/test/docs/pages/phonegap.html

Phonegap / Cordova ChildBrowser won't run Twitter web intents (SSL?)

I'm trying to integrate Twitter sharing functionality into my Android PhoneGap application, and rather than re-implement the controls to shorten URLs and track tweet length, I thought I'd use their premade web intents at https://twitter.com/intent/...
So I'm trying to launch a URL like https://twitter.com/intent/tweet?text=Hello in a ChildBrowser window, so that I can let Twitter's interface take over. The user could sign in with their credentials, and once they're signed in, the text from the URL params would appear in the Tweet box.
It won't work. When I use http://twitter.com/intent/... instead of https://twitter.com/intent/... , ChildBrowser displays the sign-in screen, but as soon as the user submits their credentials, the screen goes white. I suspect this is because Twitter switches over to HTTPS.
I confirmed that this was the case by trying a simple window.open instead of window.plugins.childBrowser.showWebPage. I have no problems with HTTP / HTTPS when using the native browser on Android. However, the native browser prompts me to accept an unverified security certificate. I suspect this is the problem with ChildBrowser - it doesn't know how to handle that prompt.
Using the native browser popover simply isn't an option: the user needs to be able to exit the process after hitting 'Tweet' or 'Follow', etc., but the 'back' button on the Android device simply moves the history one step backward to the POST action for their intent. Then, it re-launches the app from scratch, instead of returning you to the original state.
How can I configure ChildBrowser / my Android Phonegap application to override SSL issues on Twitter, so that I can run web intents in Childbrowser?
The relevant code is:
base="https://twitter.com/intent/tweet?text=";
URL=base+encodeURIComponent("it works!");
// works, but asks to accept a certificate
window.open(URL);
// blank white page
window.plugins.childBrowser.showWebPage(URL, { showLocationBar: true });
My cordova.xml file has whitelists configured as such:
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
...which I don't suspect should be a problem. However, a basic test of swapping origin=".*" yielded no change in behaviour.
I've also examined the HTTP and HTTPS headers for the Twitter intent landing pages. There doesn't appear to be anything out of line - they're identical, except for the Strict-Transport-Security header for HTTPS, which works elsewhere (e.g. Github).
Please help!
The ChildBrowser is not bound by the whitelist. The whitelist is only used to keep the main PhoneGap app from running code outside of trusted domains.
I'm confident if you go get the latest ChildBrowser code from Android you won't have run into this problem anymore. We've made some changes recently that make it more robust.
Also, Libby has a good tutorial integrating Twitter and the ChildBrowser.
http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt5p1

Categories

Resources