opening local html file with Android Browser

前端 未结 3 1613
无人共我
无人共我 2020-12-11 01:55

i\'m trying to open a local html file using the default browser using the following code:

Uri uri = Uri.fromFile(file);
Intent browserIntent = new Intent(Int         


        
相关标签:
3条回答
  • 2020-12-11 02:37
        Uri uri = Uri.fromFile(file);
        Intent browserIntent = new Intent(Intent.ACTION_VIEW);
        browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
        browserIntent.setData(uri);
        startActivity(browserIntent);
    
    0 讨论(0)
  • 2020-12-11 02:40

    I found an answer for this problem... just needed to add

    browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
    

    i used it with the "file://" uri by using Uri.fromfile(file) and it works (Android v.2.2.1)

    0 讨论(0)
  • 2020-12-11 02:50

    try this

    Intent in = new Intent(Intent.ACTION_VIEW);
                File f=new File("/sdcard/html.html");
                in.setDataAndType(Uri.fromFile(f), "text/html");
                startActivity(in);
    
    0 讨论(0)
提交回复
热议问题