当前位置:网站首页>Click the button to call the system browser to open Baidu home page

Click the button to call the system browser to open Baidu home page

2022-06-26 07:50:00 Don't hit me, it hurts!

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button1 = (Button) findViewById(R.id.button_1);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent=new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        }
    });

}

stay java Button in the file button1 Override click function

It specifies Intent Of action yes Intent.ACTION_VIEW, This is a android Actions built into the system , Constant value is android.intent.action.VIEW

And then through Uri.parse() Method , Parse the URL string into Uri The object of , Re pass Intent Of setData() take uri This object comes in

原网站

版权声明
本文为[Don't hit me, it hurts!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170609120662.html