按着例子给自己的程序添加了启动浏览器的功能。
启动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路径的问题。通过修改Android浏览器的配置文件,添加file scheme的支持,解决了程序无法正常打开file路径的情况。
9651

被折叠的 条评论
为什么被折叠?



