android中拨打电话和短信发送的实现

拨打电话功能实现核心代码:

	//phoneNumber 从输入框phoneNumber_txt获取输入的值
	String phoneNumber = phoneNumber_txt.getText().toString();
    	Log.i("DXZ号码:", phoneNumber);
	//
    	Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneNumber));
    	startActivity(intent);


发送短信功能实现核心代码:

		//android提供的发送短信类  下面使用到的mobile变量为需要接收短信息号码
  		android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
		//一条短信息最大约占的byte:中文70(包括标点),英文160,160个字节。
		if(context.length() > 70){
			//将短信内容分割成若干条短信息
			List<String> contextSMS = smsManager.divideMessage(context);
			int i = 1;
			for(String smstext:contextSMS){
				smsManager.sendTextMessage(mobile, null, smstext, null, null);
				Log.i("DXZ-发短信", "手机号:"+mobile+"内容:"+i+"-- "+smstext);
				i++;
			}
		}else{
			smsManager.sendTextMessage(mobile, null, context, null, null);
			Log.i("DXZ-发短信", "手机号:"+mobile+"内容:"+context);
		}


sendTextMessage方法的四个参数:

public void sendTextMessage(String destinationAddress,String scAddress, String text, PendingIntent sentIntent,PendingIntent deliveryIntent)
Parameters
destinationAddressthe address to send the message to
scAddressis the service center address or null to use the current default SMSC
textthe body of the message to send
sentIntentif not NULL this PendingIntent is broadcast when the message is successfully sent, or failed. The result code will beActivity.RESULT_OK for success, or one of these errors:
RESULT_ERROR_GENERIC_FAILURE
RESULT_ERROR_RADIO_OFF
RESULT_ERROR_NULL_PDU
For RESULT_ERROR_GENERIC_FAILURE the sentIntent may include the extra "errorCode" containing a radio technology specific value, generally only useful for troubleshooting.
The per-application based SMS control checks sentIntent. If sentIntent is NULL the caller will be checked against all unknown applications, which cause smaller number of SMS to be sent in checking period.
deliveryIntentif not NULL this PendingIntent is broadcast when the message is delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu").

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值