Android 调用打电话和发短信功能
2012-09-06 12:05
477 查看
Android 调用打电话和发短信功能
1.打电话可以自己写界面,在button的单击事件中添加如下代码即可:
Intent intent = new Intent();
intent.setAction("Android.intent.action.CALL");
intent.setData(Uri.parse("tel:"+ mobile));//mobile为你要拨打的电话号码,模拟器中为模拟器编号也可
startActivity(intent);
需要添加打电话权限:
<uses-permission Android:name="android.permission.CALL_PHONE" />
2.发短信
和打电话差不多,在button的单击事件中添加如下代码:
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> texts = smsManager.divideMessage(content);//拆分短信,短信字数太多了的时候要分几次发
for(String text : texts){
smsManager.sendTextMessage(mobile, null, text, null, null);//发送短信,mobile是对方手机号
}
对应发短信权限:
<uses-permissionAndroid:name="android.permission.SEND_SMS" />
附:调用系统 发送短信 和 已发送短信界面
1. 调用系统发送短信界面(并指定短信接收人和短信内容)
Uri smsToUri = Uri.parse("smsto:10086");
Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
mIntent.putExtra("sms_body", "The SMS text");
startActivity( mIntent );
2. 调用系统已发送短信界面
Uri smsUri = Uri.parse("smsto:106900867734");
Intent intent = new Intent(Intent.ACTION_MAIN, smsUri)
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
这里我们使用action_main 根据api显示提示
android.content..ACTION_MAIN = "android.intent.action.MAIN"
public static finalACTION_MAIN
Since:Activity Action: Start as a main entry point, does not expect to receive data.
Input: nothing
Output: nothing
Constant Value:"android.intent.action.MAIN"
下面这种操作其实不推荐,因为传递的smsto并无法接收。
Uri smsUri = Uri.parse("smsto:106900867734");
Intent intent = new Intent(Intent.ACTION_VIEW,smsUri)
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
根据api提示:
android.content..ACTION_VIEW = "android.intent.action.VIEW"
public static finalACTION_VIEW
Since:Activity Action: Display the data to the user. This is the most common
action performed on data -- it is the generic action you can use on a piece of data to get the most reasonable thing to occur. For example, when used on a contacts entry it will view the entry; when used on a mailto: URI it will bring up a compose window filled
with the information supplied by the URI; when used with a tel: URI it will invoke the dialer.
Input:is URI from which to retrieve data.
Output: nothing.
Constant Value:"android.intent.action.VIEW"
相关文章推荐
- Android调用系统打电话和发短信功能
- Android调用系统的打电话和发短信功能
- ios-王云鹤 调用ios系统功能---------------打电话、发短信、发邮件
- Android实现发短信与打电话的功能
- Android应用开发笔记(1):调用打电话和发短信、收短信接口、发Email
- android实现打电话和发短信的功能(10学员张晓丛)
- unity 关于打包androidjar并调用android jar包开发打电话功能的一些容易出错的点
- iOS 调用系统发短信以及打电话功能
- Android打电话与调用发短信界面
- Android应用开发笔记(1):调用打电话和发短信、收短信接口、发Email (Call, Dial, SMSManager, Broadcast, Email)
- android 调用系统打电话和发短信和发邮箱等以及得到SD卡的剩余容量
- 【XFeng安卓开发笔记】Android开发中如何调用打电话功能
- android之调用系统打电话与发短信界面
- ios 调用系统发短信以及打电话功能
- Android开发中如何调用打电话功能
- iOS 调用系统发短信以及打电话功能
- iOS 调用系统发短信以及打电话功能
- android之调用系统打电话与发短信界面
- IOS问题汇总:2015-1-9 iOS 调用系统发短信以及打电话功能
- Hello Android - 调用打电话和发短信及intent一些其他用法