使用setWebViewClient和getHitTestResult。用于获取将要打开的url,然后检查其是否为ppt文件。
第一个XML文件:-
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true">
主要活动:-
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String request)
{
try{
if(webView.getHitTestResult().getExtra().endsWith(".pptx"))
{
try
{
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("url",webView.getHitTestResult().getExtra());
startActivity(intent);
return true;
}
catch (Exception e)
{
T