如何在默认浏览器或web视图打开按钮点击网址视图、按钮、浏览器、网址

由网友(回忆里没有你)分享简介:或默认浏览器中单击一个按钮后,我怎么能打开一个的WebView的网址是什么?目前,当我点击 BTN1 按钮,它会提示我选择从手机浏览器。我想打开这个网址里面的默认浏览器,或在的WebView 。下面是我的Java code:公共类myactivity延伸活动{@覆盖公共无效的onCreate(包savedInstan...

或默认浏览器中单击一个按钮后,我怎么能打开一个的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);
          }
         }
     );
}
 

解决方案

在这里,你走了。

怎么每次打开网页的不是默认浏览器

请确保包括<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/> 在清单

 意图int​​ernetIntent =新的意图(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);