//拨打电话
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri=Uri.parse("tel:1008611");
Intent it=new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
}
});
//发送短信
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri=Uri.parse("smsto:10086");
Intent it=new Intent(Intent.ACTION_SENDTO,uri);
it.putExtra("sms_body","代开发票");
// it.setType("vnd.android-dir/mns-sms");
startActivity(it);
}
});
//打开网页
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri=Uri.parse("http://www.baidu.com");
Intent it=new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
}
});
//打开图片
bt4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it=new Intent(Intent.ACTION_VIEW);
File file=new File("/sdcard/aaa.jpg");
it.setDataAndType(Uri.fromFile(file),"image/*");
startActivity(it);
}
});
//打开音乐
bt5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it=new Intent(Intent.ACTION_VIEW);
File file=new File("/sdcard/bbb.mp3");
it.setDataAndType(Uri.fromFile(file),"audio/*");
startActivity(it);
}
});
//安装应用
bt6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it=new Intent(Intent.ACTION_VIEW);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
it.setDataAndType(Uri.parse("file:///sdcard/abc.apk"),"application/vnd.android.package-archive");
startActivity(it);
}
});
隐式Intent调用
最新推荐文章于 2024-07-06 12:48:11 发布