How to copy and run an html5 file present in andoid app

Put your problem here if it does not fit any of the other categories.

How to copy and run an html5 file present in andoid app

Postby shailaja » Mon Feb 13, 2012 1:56 pm

I am developing an android application, that should open html 5 file when it launches. What I did was

I saved the complete html application under android Assets folder.

I am not able to run the html file in the external browser using the path of assets folder directly, Following is the code I used
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     Intent browserIntent = new Intent("android.intent.action.VIEW",
  2.                      Uri.parse("file:///android_assets/mobile/index.html"));
  3.     startActivity(browserIntent);
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


An exception is thrown.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. java.lang.RuntimeException: Unable to start activity ComponentInfo android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= file:///android_assets/mobile/index.html }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



So now I want to send this folder to phone’s internal memory and From there I want to run it.

Qn 1. How can I send a file into phone memory?

Qn 2. And can I run that html file from phone memory?

Is it possible to do so??
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Top

Re: How to copy and run an html5 file present in andoid app

Postby Phyll » Mon Feb 13, 2012 10:44 pm

Hi shailaja,

Here is some code I'm using to copy from assests to sdcard. Maybe it will help. Might need a little modification to work in the /data/data/package folder.

Code: Select all
    String dataPath = "/sdcard";

    private void copyFromAssets(String fromFile, String toFile) { //if toFile empty this will
         InputStream ips;                                          //make it same as fromFile
         String toTemp = toFile;
         if (toTemp.length() == 0) toTemp = fromFile;
      try {
         ips = this.getAssets().open(fromFile);

             String outFileName = dataPath + "/" + toTemp;
             OutputStream ops = new FileOutputStream(outFileName);
             byte[] buffer = new byte[1024];
             int length;
             while ((length = ips.read(buffer))>0){
                ops.write(buffer, 0, length);
                 }//while
             ops.flush();
             ops.close();
             ips.close();
          } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
              }//catched
          }//copy from assets


Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests