Android 调用平台功能 - 启动浏览器 支持file://

按着例子给自己的程序添加了启动浏览器的功能。

启动http://的完全没有问题,启动file://就总是异常

最后发现问题出在了Android 浏览器的配置文件上

自己的调用程序:

  Uri uri = Uri.parse("file://data/data/test.html");        
  Intent it = new Intent(Intent.ACTION_VIEW, uri);        
  context.startActivity(it);     

Android 浏览器的配置文件:

packages\apps\Browser\AndroidManifest.xml

            <!-- For these schemes were not particular MIME type has been
                 supplied, we are a good candidate. -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:scheme="about" />
                <data android:scheme="javascript" />
            </intent-filter>
            <!--  For these schemes where any of these particular MIME types
                  have been supplied, we are a good candidate. -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:scheme="inline" />
                <data android:mimeType="text/html"/>
                <data android:mimeType="text/plain"/>
                <data android:mimeType="application/xhtml+xml"/>
                <data android:mimeType="application/vnd.wap.xhtml+xml"/>
            </intent-filter>

果然是没有file的scheme,加上程序就过了。

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="file" />
            </intent-filter>

你可能感兴趣的:(android,浏览器,File,Scheme,action,平台)