【Intent】Android系统Intent使用大全(持续更新中...)
来源:互联网 发布:win10 telnet 端口 编辑:程序博客网 时间:2024/05/17 09:01
官方Intent api地址:
http://developer.android.com/intl/zh-cn/guide/components/intents-common.html
★ 拨打电话
1. 跳转至系统拨号盘界面
Intent intent = new Intent(Intent.ACTION_DIAL);Uri uri = Uri.parse("tel:"+"手机号");intent.setData(uri);startActivity(intent);
2. 直接调用拨打电话
Intent intent = new Intent(Intent.ACTION_CALL);Uri uri = Uri.parse("tel:"+"手机号");intent.setData(uri);startActivity(intent);
★ 发送短信
1. 跳转至系统发送短信界面Intent intent = new Intent(Intent.ACTION_SENDTO);Uri uri = Uri.parse("smsto://"+"手机号");intent.setData(uri);intent.putExtra("sms_body", "短信内容");startActivity(intent);
2. 调用系统短信接口直接发送短信
/** * 直接调用短信接口发短信 * @param phoneNumber * @param message */public void sendSMS(String phoneNumber,String message){//获取短信管理器 android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();//拆分短信内容(手机短信长度限制) List<String> divideContents = smsManager.divideMessage(message); for (String text : divideContents) { smsManager.sendTextMessage(phoneNumber, null, text, null, null); }}
★ 打开手机浏览器
调用手机浏览器,大部分人会使用如下代码:
Intent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);Uri content_url = Uri.parse(url);intent.setData(content_url);startActivity(intent);
但是这样做并不严谨,如果手机上没有安装浏览器APP的话,系统就会因为找不到这个Action对应的Activity而发生崩溃问题!
使用Intent对象的resolveActivity(PackageManager pm)方法可以检测手机端是否有对应Activity来启动该Intent,如下:
public void openWebPage(String url) { Uri webpage = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }}
如果以上代码,将会打开手机端默认的浏览器,如果想让用户自己选择使用哪一个浏览器的话,可以使用Intent的createChooser(Intent target, CharSequence title)方法:
Intent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);Uri content_url = Uri.parse("http://www.jianshu.com/p/eaae783b931f");intent.setData(content_url);if (intent.resolveActivity(getPackageManager())!=null) { startActivity(Intent.createChooser(intent, "请选择浏览器"));}
0 0
- 【Intent】Android系统Intent使用大全(持续更新中...)
- android系统调用 Intent的使用大全
- android 中 intent和intent action大全
- Android系统常用Intent大全
- Android系统Intent调用大全
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- Android系统中标准Intent的使用
- 设计模式_享元模式
- 1001
- 插排最优情况
- 使用 C# 开发智能手机软件:推箱子(三)
- HDU 1501 Zipper(DFS)
- 【Intent】Android系统Intent使用大全(持续更新中...)
- const对象和const函数的用法限制以及对const成员变量或引用的初始化问题
- 使用 C# 开发智能手机软件:推箱子(四)
- MD5加密用法实现
- Io流
- 条款37 绝不要重新定义继承而来的缺省参数值
- Ubuntu Server 安装&配置 Apache-Tomcat
- 字符串匹配 CCF KMP算法实现字符串匹配
- 从xml文件读数据