posts - 71,  comments - 203,  trackbacks - 0
private void sendSMS() {
String smsAddress
= "10086";
String smsBody
= "bylcx";
SmsManager smsMag
= SmsManager.getDefault();
Intent sendIntent
= new Intent(ACTION_SMS_SEND);
PendingIntent sendPI
= PendingIntent.getBroadcast(this, 0, sendIntent,
0);
Intent deliveryIntent
= new Intent(ACTION_SMS_DELIVERY);
PendingIntent deliveryPI
= PendingIntent.getBroadcast(this, 0,
deliveryIntent,
0);
smsMag.sendTextMessage(smsAddress,
null, smsBody, sendPI, deliveryPI);
}
package lab.sodino.smslistener;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SmsAct extends Activity {
private TextView textView;
private static String ACTION_SMS_SEND = "lab.sodino.sms.send";
private static String ACTION_SMS_DELIVERY = "lab.sodino.sms.delivery";
private SMSReceiver sendReceiver;
private SMSReceiver deliveryReceiver;

public class SMSReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String actionName
= intent.getAction();
int resultCode = getResultCode();
if (actionName.equals(ACTION_SMS_SEND)) {
switch (resultCode) {
case Activity.RESULT_OK:
textView.append(
"\n[Send]SMS Send:Successed!");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
textView
.append(
"\n[Send]SMS Send:RESULT_ERROR_GENERIC_FAILURE!");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
textView
.append(
"\n[Send]SMS Send:RESULT_ERROR_NO_SERVICE!");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
textView.append(
"\n[Send]SMS Send:RESULT_ERROR_NULL_PDU!");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
}
}
else if (actionName.equals(ACTION_SMS_DELIVERY)) {
switch (resultCode) {
case Activity.RESULT_OK:
textView.append(
"\n[Delivery]SMS Delivery:Success!");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
textView
.append(
"\n[Delivery]SMS Delivery:RESULT_ERROR_GENERIC_FAILURE!");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
textView
.append(
"\n[Delivery]SMS Delivery:RESULT_ERROR_NO_SERVICE!");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
textView
.append(
"\n[Delivery]SMS Delivery:RESULT_ERROR_NULL_PDU!");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
textView
.append(
"\n[Delivery]SMS Delivery:RESULT_ERROR_RADIO_OFF!");
break;
}
}
}
}
posted on 2011-06-13 09:58  stay  阅读(1381)  评论(0编辑  收藏