android - 如何在默认浏览器或 webview 中打开按钮点击 url

标签 android android-layout android-intent

单击按钮后如何在 webview 或默认浏览器中打开 url?目前,当我单击 btn1 按钮时,它会提示我从手机中选择一个浏览器。我想在默认浏览器或 webview 中打开此 url。

这是我的java代码:

 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);
          }
         }
     );
}

最佳答案

给你。

确保包含 <uses-permission android:name="android.permission.INTERNET"/>在 list 中

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);

关于android - 如何在默认浏览器或 webview 中打开按钮点击 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031348/

相关文章:

java - Android 通过多种布局进行导航

java - 从 FileObserver 启动 IntentService

java - 有什么办法可以获取listView中的特定 View 吗?

android - 如何删除默认布局的填充/边距

android - 如何将消息从后台服务发布到 UI fragment ?

android - 如何在 Android 浏览器中检查元素

android - 无法从数据库中获取数据并有意传递

android - 如何在android中获取getActionBar对象?

java - 重命名K9邮件包名称

javascript - 如何在三星 galaxy S2 中查看控制台日志输出