How to load local html page using intent in Android?

I have an html file in my resource directory and I have to upload it as a browser using Intent.

Here is my code, but its not working:

startActivity (new Intent(Intent.ACTION_VIEW, 
               Uri.parse("file:///android_asset/Sample.htm")));

Can anyone help me?

+5
source share
2 answers

Use loadUrl()method WebViewto load html page

Example example if faq.html is an html file present in the resource folder, then you can use

WebView html = (WebView) findViewById(R.id.webEulaView);
html.loadUrl("file:///android_asset/faq.html");
0
source

I had the same problem as me. copied the contents of the assets to the database and then pulled it out of sdcard

SDCard : html- zip content - zip

    boolean succussFlag = false; 
    destination="";
    destination=Environment.getExternalStorageDirectory()+"/";
    File file = new File(destination);

    if (!file.exists()){
        file.mkdirs();
    }
    else
    {
        //file.delete();
        //file.mkdir();
    }
    try
    {
        InputStream fileInput = context.getAssets().open("content.zip");
        ZipInputStream inputStream = new ZipInputStream(fileInput);

        for (ZipEntry entry = inputStream.getNextEntry(); entry != null; entry = inputStream.getNextEntry())
        {
            String innerFileName = destination +  entry.getName();
            System.out.println("destination::::"+innerFileName);
            //              Log.v("inner file name 0",""+innerFileName);
            File innerFile = new File(innerFileName);
            if (innerFile.exists())
            {

                innerFile.delete();
            }

            // Check if it is a folder
            if (entry.isDirectory())
            {
                // Its a folder, create that folder
                innerFile.mkdirs();
            }
            else
            {
                //                  System.out.println(" ::::::::::::::INNER FILE COPYING :::: " + innerFile.toString());
                FileOutputStream outputStream = new FileOutputStream(innerFileName);
                final int BUFFER = 4096;

                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream,
                        BUFFER);

                int count = 0;
                byte[] data = new byte[BUFFER];
                while ((count = inputStream.read(data, 0, BUFFER)) != -1)
                {
                    bufferedOutputStream.write(data, 0, count);
                }
                bufferedOutputStream.flush();
                bufferedOutputStream.close();
            }

            inputStream.closeEntry();
        }
        inputStream.close();
        //          System.out.println(" ::::::::::COPIED TO PRIVATE FOLDER ::::  " );
        succussFlag=true;
    }
    catch (IOException e)
    {
        //          System.out.println("** EXCEPTION OCCURED WHILE COPYING***");
        e.printStackTrace();
        succussFlag=false;
    }

    return succussFlag;

startActivity (new Intent(Intent.ACTION_VIEW,"file://"+     Environment.getExternalStorageDirectory()+"/content"+name_Html ;
         );
0

All Articles