Android - cordova - A network error has occurred - javascript

My Environment
Android Studio 1.0.1
cordova-4.1.0
I'm trying to access my website at http://example.com/index.php from the line super.loadUrl(Config.getStartUrl());
As the application runs on My physical device (Moto g2, Android 5) splash screen to MainActivity extends CordovaActivity works fine but on MainActivity it shows a alert with a title: Application Error and body: There was a network error. (http://example.com/index.php)
I have set the needed permission for Internet Access AndroidManifest.xml
Recently i have updated cordova from 2.9 to 4.1.; Log cat doesn't show's any record related to my application while running application. Also i tried to replace "http://example.com/index.php" with the "file:///android_asset/www/example.html" which worked fine, so i made a change in it and redirected to "http://example.com/index.php" form onLoad or by giving link it from example.html page but it fails to redirect.
anybody has a solution or a trick to solve it?

Add www before example. like this http://www.example.com/index.php it should work.
If still it is not working try debugging using chrome. This link might help you
http://www.html5rocks.com/en/tutorials/developertools/mobile/

Related

Intel xdk function (cookie) works fine in emulator, but doesnt work in device even i have put <script src="intelxdk.js"></script> tag in index.html

I am trying to test cookie in device, so i build a simple application.
I have tested it on emulator and works fine.
but when i test it in apps testing server, and in device, All the Intel xdk function doesnt work (I just want test cookie),
I have put script <script>src="intelxdk.js"</script> in index.html.
But it doesnt work also, i have searched here,
intel-xdk html5 platform android aplication working properly in emulator but not working properly in device , so i include the <script src="xhr.js"></script> but it doesnt work also
My code is:
(Sorry, im just new here and cant post image if post under 10. Here the image)
http://helpmedong.esy.es/
The alert is still : Intel is not defined..
thx before..
ive found the problem.
I click "Project" button =>
then click +plugin tab =>
featured and custome cordova plugins =>
check the cache option.
Thx everyone.
And then put the coding in deviceready.
About my comment above and with cheyong help, I go to this way...
If you begin with project withou Cordova you click second option
But, in this way haven't plugins choice:
Than upgrade...
Note the option "plugins"

xdk button doesn't do anything

I'm testing my app on a Galaxy Tab 2.
I have a button which looks like this in the code:
<button class='msdsBtn' onclick='launchGoogle();'>msds</button>
// test function
function launchGoogle(){
alertw("launch google");
intel.xdk.device.launchExternal("http://www.google.com");
}
// wrapper for xdk alert
function alertw(str){
intel.xdk.notification.alert(str);
}
the button doesn't do anything. No errors, no opening of Google, no alert box... nothing.
These buttons are dynamically created on the page.
Am I missing something? I should note that it all works in the emulator.
Do you have the proper plugin ("Notification", I believe, in this case) checked in your project settings?
I wouldn't spend too much time figuring out how to make this call work, as Intel is deprecating the XDK APIs that are redundant with Cordova APIs.
Instead, try switching out your notification calls with the equivelent Cordova method. It should look something like this:
navigator.notification.alert(message, alertCallback, [title], [buttonName])
And again, make sure you have the right plugin configured in your project settings ("Dialogs"). Your project settings can be accessed through the XDK IDE by clicking "Projects" in the upper left corner.
Here is the full documentation for the Cordova dialogs API:
https://github.com/apache/cordova-plugin-dialogs/blob/master/doc/index.md
EDIT: And as Ian says above, you can of course debug your app as it runs on a device through the Debug tab for Android, and with WEINRE on other platforms.

Unable to open appstore link (PhoneGap)

Tried both of the following methods so that ppl can click a link in my app and be taken to the app store to review/rate:
Rate our App
and when this linked is tapped on, nothing happens and i get the following console message:
Failed to load webpage with error: The URL can’t be shown
Also tried a window.open:
$(document).hammer().on('tap', self.frameSelector + ' .rate-us-action', function(){
window.open('itms-apps://itunes.apple.com/app/id111111111');
});
and when tapping attempting this method nothing happens and i get the following console message:
handle url: itms-apps://itunes.apple.com/app/id1111111
How do i get my phonegap app to properly open a link to the appstore???
Try this format for <> has to be replaced with the appropriate info:
http://itunes.apple.com/app/<APP_NAME>/id<APP_ID>?mt=8
I've used the following link format for Cordova/PhoneGap apps since Cordova 2.2 & iOS 5:
itms-apps://itunes.com/apps/appname
Simply replace appname with your app's name.
Rate our App
You can also open the App Store and display a page of apps by your company with the same format:
itms-apps://itunes.com/apps/companyname
In a link:
More Apps By Us
This works today on iOS 8.1.1 without the Cordova inappbrowser plugin.

White screen when running Cordova 2.6.0 project on Xcode

I have this problem. It's intermittent though but I fear future user of my app will experience it too and I don't want that. I upgraded to cordova-2.6.0. I'm now experiencing a problem when running my application on an iPad.
On the Console everything seems to be working. The splashscreen display's properly but after the splashscreen (intermittent) index.html doesn't load or its plain white screen.
So here is what I see on the console :
Multi-tasking -> Device: Yes, App: YES
Resetting Plugins due to page load.
Finished load of: file:///var/mobile/Applications/(numbers)/Project.app/www/index.html
DEPRECATION NOTICE: The Connection ReachableViaWWAN return value of '2g' is deprecated as of Cordova version 2.6.0 and will be changed to 'cellular' in a future release.
Then whitescreen!! ( Just like the white walkers. lol )
Anyways on my Cordova-2.6.0.js I changed the xhr.open
from: xhr.open('GET', 'cordova_plugins.json', true);
to : xhr.open('GET', 'file:///cordova_plugins.json', true);
Only because I can't test my app on a browser. Just googled the fix though.
Any Ideas? Thanks
The error might not be connected to the deprecation notice. I have been getting that notice in iPhone with no issues.
Check if you have all the required splash screen files for iPad and added those to config.xml:
https://build.phonegap.com/docs/config-xml

Ti.App.fireEvent - Reference error Ti is not defined

I have this simple Titanium js script.
app.js
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'logging.html'
});
webview.addEventListener('help',function(){
alert('help');
});
win.add(webview);
win.open();
logging.html
<html>
<body>
<a onclick="Ti.App.fireEvent('help')">Help</a>
</body>
</html>
when I click on the Help link, the console gives me Reference Error: Ti is not defined.
I also tried changing Ti with Titanium, but same error.
------------- EDIT ----------
this error comes only with web browser. iOS works perfectly. but
when titanium studio compiles the project for web mobile, I can see titanium.js and TI/* folder, so I guess it can't load Ti object. can anyone explain me why?
I found a solution!
simply add to all of your html pages the simple script below
var Ti = window.parent.Ti
have fun!
EDIT:
from sdk version 3.0.2GA on, I guess they fixed it. now it calls Ti sdk without that hack!**
First, change:
webview.addEventListener('help',function(){
alert('help');
});
To:
Ti.App.addEventListener('help',function(){
alert('help');
});
And second: Call "Ti.App.fireEvent()" without the final "s" in your HTML file.
after some tests, I found that the previous code works perfectly on iOS phisical device/simulator and Android.
it doesn't on android web browser emulator and normal mobile browser (Firefox as mobile web app)
so, it seems that Titanium api calls will never work on web browsers because of "normal javascript library doesn't have Titanium.* or Ti.*".
I used this and it worked
window.parent.TiApp.fireEvent

Categories