如何加载在Android中使用的意图当地的html页面? [英] How to load the local html page using intent in Android?

查看:119
本文介绍了如何加载在Android中使用的意图当地的html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的资产目录中的HTML文件,我必须把它作为加载使用意向浏览器应用程序。

I have a html file in my asset directory and i have to load it as browser application using Intent.

下面是我的code,但它不工作:

Here is my code, but its not working:

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

谁能帮助我?

推荐答案

我有同样的问题,我所做的就是
复制的资产与一个数据库中的内容,然后从SD卡

i had the same problem what i did was copied the content of the assets to a database and then pulled it from the sdcard

这里是code复制你的资产到SD卡
所使用的逻辑如下的HTML页面放置在压缩文件中的资产文件夹
内容资产的文件夹压缩

here is the code to copy your assets to sdcard the logic used is as follows the html pages are put in the zip file in assets folder content is the name of the zip in assets folder

    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;

在这之后你给下面的命令

after this you give following command

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

这篇关于如何加载在Android中使用的意图当地的html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆