在Actity内打开系统浏览器,电话

2019-06-21  本文已影响0人  木木不哭_8be4
package com.lhp.basic;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button btnBaidu,call;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnBaidu=findViewById(R.id.btn_open_baidu);
        call=findViewById(R.id.btn_call);

        btnBaidu.setOnClickListener(new ButtonListener());
        call.setOnClickListener(new ButtonListener());



    }
    //监听事件
    private class  ButtonListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch(v.getId()){
                case R.id.btn_call:
                    Intent intent= new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse("tel:10086"));
                    startActivity(intent);
                    break;
                case R.id.btn_open_baidu:
                    Intent intent1=new Intent(Intent.ACTION_VIEW);//设置Action
                    intent1.setData(Uri.parse("http://www.baidu.com"));
                    startActivity(intent1);
                    break;
                default:
                    finish();//关闭Acticty

            }

        }
    }
}

上一篇下一篇

猜你喜欢

热点阅读