How to launch browser to open local file

前端 未结 7 1270
孤街浪徒
孤街浪徒 2020-12-10 05:20

I\'m trying to send intent to browser to open local file. I wish to use default browser to open this file.

if(file.exists()){
  Log.d(TAG, \"file.exists\");         


        
相关标签:
7条回答
  • 2020-12-10 06:16

    This code works on both API 10 and API 11.

    File f = new File("/mnt/sdcard/index.html");
    
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setDataAndType(Uri.fromFile(f), "application/x-webarchive-xml");
    // Have to add this one in order to work on Target 2.3.3 (API 10)
    intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
    startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题