SmsManager成功

时间:2011-05-06 08:31:40

标签: android

我正在使用以下代码发送短信。但是,当没有发送短信时,这似乎不会产生异常。例如,当没有足够的钱来发送它时,我仍然会去smsSucces();有没有人知道如何确定它已被发送?

    private boolean composeSms(String telefoonnr, String boodschap) {
    if(telefoonnr.equals("") || boodschap.equals(""))   {
        smsFail();
        return false;
    }
    try {
    SmsManager sm =  SmsManager.getDefault();
    //PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SmsActivity.class), 0);   
    sm.sendTextMessage(telefoonnr, null, boodschap, null, null);
    DataClass dc = (DataClass) getApplicationContext();
    dc.setBoolean(DataClass.ACTIVATED_SMS, true);
    dc.setString(DataClass.SMS_NUMBER, telefoonnr);
    Log.d("temp","sms send succesfully");
    smsSucces();
    return true;
    }
    catch (Exception e) {
        e.printStackTrace();
        smsFail();
        return false;
    }


}

2 个答案:

答案 0 :(得分:1)

您好,您可以使用广播短信发送报告     `

以下是此

的代码

//短信发送待处理意图

PendingIntent deliveredIntent = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED_ACTION), 0);

//短信发送接收器

registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "SMS sent intent received.");
}
}, new IntentFilter(SENT_ACTION));

//短信发送接收器

registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "SMS delivered intent received.");
}
}, new IntentFilter(DELIVERED_ACTION));

答案 1 :(得分:0)