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
destinationAddress the address to send the message to
scAddress is the service center address or null to use the current default SMSC
text the body of the message to send
sentIntent if 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.
deliveryIntent if 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").

 

你可能感兴趣的:(android,String,null,mobile,sms,电话)