欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

intent对于电话和浏览器调用

程序员文章站 2024-01-23 22:25:16
...

1、创建xml文件及按钮LinearLayout xmlns:android=http://schemas.android.com/apk/res/androidandroid:orientation=verticalandroid:layout_width=match_parentandroid:layout_height=match_parentButtonandroid:id=@+id/intentbtnandroid:layout_width=fil

1、创建xml文件及按钮





2、新创建一个Intent的java文件

ublic class Intent_s extends Activity {

//定义两个属性
private Button mbutton,callbutton;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intent);

//初始化属性
mbutton = (Button) findViewById(R.id.intentbtn);
callbutton=(Button)findViewById(R.id.intentbtncall);

//监听intent调用电话的按钮
callbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//标示地址
Uri uri = Uri.parse("tel:13881715535");

//新创建intent调用
Intent it = new Intent(Intent.ACTION_DIAL, uri);

//启动
startActivity(it);
}
});

//监听intent调用浏览器的监听
mbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//标示地址
Uri uri = Uri.parse("http://www.baidu.com");

//新创建intent
Intent intent = new Intent();

//调用intent
intent.setAction(Intent.ACTION_VIEW);

//向intent放入数据
intent.setData(uri);

//启动
startActivity(intent);
}
});
}