Android之调用系统应用

本文详细介绍了如何通过代码调用手机系统进行打电话、发短信、查看图像、拍照、录像和浏览网页等基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用系统打电话:

String phone = "110";
Intent intent = new Intent();
//系统默认的action,用来打开默认的电话界面
intent.setAction(Intent.ACTION_CALL);
//需要拨打的号码
intent.setData(Uri.parse("tel:"+phone));
startActivity(intent);
调用系统发短信:

String phone = "110";
Intent intent = new Intent();
//系统默认的action,用来打开默认的短信界面
intent.setAction(Intent.ACTION_SENDTO);
//需要发短息的号码
intent.setData(Uri.parse("smsto:"+phone));
startActivity(intent);
String phone = "110";
String content = "救命啊";
Uri uri = Uri.parse("smsto:"+phone);  
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);  
intent.putExtra("sms_body", content);  
startActivity(intent);

调用系统查看图像

File file=new File(path);  //path为图像路径
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.addCategory("android.intent.category.DEFAULT");   
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);

调用系统拍照

String fileName = System.currentTimeMillis() + ".jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
newImagePath = UrlPath.imgPath + fileName;
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), fileName));
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, 1);

调用系统录像

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(intent, 1);

调用系统浏览网页

String url = "http://www.baidu.com";
Uri uri = Uri.parse(url); 
Intent it  = new Intent(Intent.ACTION_VIEW,uri); 
startActivity(it); 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值