Java / Android Developer, Trainer, Writer, Speaker

Monday, December 1, 2014

Like the article?

Hello mobile apps developers! if you are developing Mobile application in Phonegap platform. You might  face a problem in sometime  ' Connection to the server was unsuccessful. (file ///android_asset/www/index.html)  '


Phonegap problem


Well, I have couple of simple solution for you guys on this note.

Solution 1:
This might happen for extended loading time. You can add some time for loading. The problem will be solved. Process of doing that is :

    Just after  super.loadUrl("file:///android_asset/www/index.html");
Add below line:       

super.setIntegerProperty("loadUrlTimeoutValue", 7000);
   
Here, I'm giving 7 seconds to the system for loading the files. You can increase the time. But, users will face some kind of problem here. They will have to wait this amount of time after opening the application. For that I've another solution. I experimented this solution, and this worked nicely. You can give a try too.

Solution 2:
Call a simple HTML file from MainActivity.java and call your ' index.html ' file from that simple HTML file. For that:
Firstly, create a new html file naming rubel.html and paste below codes into that file:

<!doctype html>
<html>
  <head>
   <script>
     window.location='./index.html';
   </script>
</head>
  <body>
  </body>
</html>
Secondly, Rename the code line super.loadUrl("file:///android_asset/www/index.html"); to super.loadUrl("file:///android_asset/www/rubel.html"); from your MainActivity.java File. And keep the rest same!

Now, clean, refresh and build! Hope, this helps you!

Comment if you face any problem!
Subscribe for you!
Share for others!

5 comments:

  1. Thanks, the second helped for Cordova app. Need to redirect from a simple page to the page you intend to load.

    ReplyDelete
  2. Kalau buwat file tnpa mengunakan pc bagai mana?? Tolong bantu kami. Terimakasih.

    ReplyDelete
  3. Just run app over old emulator like Android 4.4..... or use real android handset !!!

    ReplyDelete
  4. Hello AM unable to Find out how i can write those files and where do i paste in Android/src/com/myapp/mainActivity.java

    super.loadUrl("file:///android_asset/www/rubel.html");

    ReplyDelete