Last active
April 8, 2020 23:45
-
-
Save tomoyamkung/5770426 to your computer and use it in GitHub Desktop.
[Android]WebView に表示されているリンクをデフォルトブラウザで開く
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* (non-Javadoc) | |
* @see android.app.Activity#onCreate(android.os.Bundle) | |
*/ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// : | |
// : | |
WebView webView1 = (WebView)findViewById(R.id.webView1); | |
webView1.setWebViewClient(new WebViewClient() { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
// URL が "http://" で始まっていたらデフォルトブラウザで開く | |
if (url != null && url.startsWith("http://")) { | |
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
}); | |
// : | |
// : | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment