2012-04-23 64 views

回答

0

AFAIK,你將無法知道鏈接是什麼。有一種方法可以知道用戶點擊的webview鏈接,它是WebViewClient

這裏是一個代碼,你可以知道點擊鏈接有XLS文件或PDF文件或其他。您也可以使用該代碼阻止鏈接

public class TestingActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     WebView view = new WebView(getApplicationContext()); 
     view.setWebViewClient(new MwebViewClient()); 
    } 

    class MwebViewClient extends WebViewClient { 
    @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if(url.contains(".xls")) { 
      Log.d("Blah", "This link contains XLS file"); 
     } 
     return super.shouldOverrideUrlLoading(view, url); 
     } 
    } 
}