它是一个通过json api查看wordpress网站的应用程序,但问题是,当我点击它在应用程序中打开的链接我想在外部浏览器上打开它像铬...等等
这是webview的代码
// Get Web view
mWebView = (WebView) rootView.findViewById(R.id.webView); //This is the id you gave to the WebView in the main.xml
pBar = (ProgressBar) rootView.findViewById(R.id.pbLoader); //This is the id you gave to the WebView in the main.xml
pBarText = (TextView) rootView.findViewById(R.id.pbLoaderText);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowContentAccess(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.getSettings().setDefaultTextEncodingName("utf-8");
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this //if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
if (savedInstanceState == null) {
if (getArguments().getString("httpURL") == null) {
httpURL = null;
} else {
httpURL = getArguments().getString("httpURL");
}
} else {
httpURL = (String) savedInstanceState.getSerializable("httpURL");
}
mWebView.loadUrl(httpURL);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
//Make the bar disappear after URL is loaded, and changes string to Loading...
pBarText.setText("Loading... (" + (progress) + "%)");
pBar.setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if (progress == 100) {
pBar.setVisibility(View.GONE);
pBarText.setVisibility(View.GONE);
}
}
});
return rootView;
}
}
我想告诉我我会改变什么
答案 0 :(得分:0)
如果您想在Chrome等浏览器中打开该链接,请删除所有代码,然后在外部浏览器中打开您的链接,如下所示:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(your_link));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
// Chrome browser presumably not installed so open the default browser
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(your_link)));
}