如何在默认浏览器或web视图打开按钮点击网址 [英] How to open button click url in default browser or webview
本文介绍了如何在默认浏览器或web视图打开按钮点击网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
或默认浏览器中单击一个按钮后,我怎么能打开一个的WebView的网址是什么?目前,当我点击
BTN1
按钮,它会提示我选择从手机浏览器。我想打开这个网址里面的默认浏览器,或在的WebView
。
下面是我的Java code:
公共类myactivity延伸活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
按钮BT1 =(按钮)findViewById(R.id.btn_click_login);
btn_login.setOnClickListener(新OnClickListener(){
公共无效的onClick(视图v){
意图myWebLink =新的意图(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse(http://google.com));
startActivity(myWebLink);
}
}
);
}
解决方案
在这里,你走了。
请确保包括<使用-权限的Android:名称=android.permission.INTERNET对/>
在清单
意图internetIntent =新的意图(Intent.ACTION_VIEW,
Uri.parse(http://www.google.com));
internetIntent.setComponent(新单元名(com.android.browser,com.android.browser.BrowserActivity));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(internetIntent);
How can I open an url in a webview
or in the default browser after clicking a button? Currently, when I click the btn1
button it prompts me to select a browser from the phone. I want to open this url inside the default browser or in a webview
.
Here is my java code:
public class myactivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bt1 = (Button) findViewById(R.id.btn_click_login);
btn_login.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://google.com"));
startActivity(myWebLink);
}
}
);
}
解决方案
Here you go.
Make sure to include <uses-permission android:name="android.permission.INTERNET"/>
in manifest
Intent internetIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
internetIntent.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(internetIntent);
这篇关于如何在默认浏览器或web视图打开按钮点击网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文