短信发送应用/待定意图

时间:2012-11-19 12:47:26

标签: android android-intent android-pendingintent


我有从Android发送短信的App。
代码1

    SmsManager sms = SmsManager.getDefault();
    Intent intent = new Intent("smsSend");
    intent.putExtra("id", id);
    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    sms.sendTextMessage(phoneNo, null, messageText, null, null);
    SendDbUserDao.getInstance(SmsSendIntentService.this).updateSendSMSStatus(intent.getExtras().get(Constants.id).toString(), Constants.sendStatus);

代码2

SmsManager sms = SmsManager.getDefault();
    Intent intent = new Intent("smsSend");
    intent.putExtra("id", id);
    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    if(messageText.isEmpty()){
        SendDbUserDao.getInstance(SmsSendIntentService.this).updateSendSMSStatus(id, Constants.sendStatus);
    }else {
        System.out.println("SmsSendIntentService.sendSms()" + id); 
        sms.sendTextMessage(phoneNo, null, messageText, sentPI, null);
        }

听众类

public class SmsSendListener extends BroadcastReceiver {

String tag="SmsSendListener";

@Override
public void onReceive(Context context, Intent intent) {
    switch (getResultCode()) {
    case Activity.RESULT_OK:
        if (intent.getExtras() != null) {
            Log.i("Message Send Confirmation", intent.getExtras().get(Constants.id).toString());
            SendDbUserDao.getInstance(context).updateSendSMSStatus(intent.getExtras().get(Constants.id).toString(), Constants.sendStatus);
        }
        break;
    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
        Toast.makeText(context,"SMS Sending Error :Generic failure" ,Toast.LENGTH_SHORT).show();
        break;
    case SmsManager.RESULT_ERROR_NO_SERVICE:
        Toast.makeText(context,"SMS Sending Error :No service" ,Toast.LENGTH_SHORT).show();
        break;
    case SmsManager.RESULT_ERROR_NULL_PDU:
        Toast.makeText(context,"SMS Sending Error :Null PDU" ,Toast.LENGTH_SHORT).show();
        break;
    case SmsManager.RESULT_ERROR_RADIO_OFF:
        Toast.makeText(context,"SMS Sending Error :Radio off" ,Toast.LENGTH_SHORT).show();
        break;
    }
}

问题1:逻辑上代码1和代码2是一样的吗?
问题2:两者的输出是非常不同的代码1只发送一次短信到每个数字但代码2发送多次!!!为什么?

0 个答案:

没有答案
相关问题