2012-03-22 7 views
7

documentazione Android per SMSManagers sendTextMessage funzioneCome "deliveryIntent" funziona nel framework SMS di Android?

public void sendTextMessage (String destinationAddress, String scAddress, String text,   
PendingIntent sentIntent, PendingIntent deliveryIntent) 

deliveryIntentse non nullo questo PendingIntent viene trasmesso quando il messaggio viene recapitato al destinatario. Il raw pdu del rapporto di stato è nei dati estesi ("pdu")

Non riuscivo a capire se deliveryIntent è attivato quando l'SMS viene consegnato a destinationAddress o scAddress e qual è il significato di "raw pdu dello stato il rapporto è nei dati estesi ("pdu") "e come ottenere quel rapporto? .

Apprezzo il tuo impegno.

risposta

3

Viene trasmesso quando il messaggio viene recapitato al destinationAddress.

Intent.getExtras().get("pdu") può essere estratto dallo Intent.getExtras().get("pdu") quando registrato BroadcastReceiver riceve la trasmissione Intent definita con PendingIntent.getBroadcast(Context, int requestCode, Intent, int flags). Per esempio:

private void sendSMS(String phoneNumber, String message) {  
    String DELIVERED = "DELIVERED"; 

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, 
     new Intent(DELIVERED), 0); 

    registerReceiver(
     new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context arg0, Intent arg1) { 
       Object pdu = arg1.getExtras().get("pdu"); 
       ... // Do something with pdu 
      } 

     }, 
     new IntentFilter(DELIVERED));   

    SmsManager smsMngr = SmsManager.getDefault(); 
    smsMngr.sendTextMessage(phoneNumber, null, message, null, deliveredPI);    
} 

allora avete bisogno di analizzare estratto PDU, SMSLib dovrebbe essere in grado di farlo.

2

Giusto per costruire su risposta di a.ch, ecco come si può estrarre il rapporto di consegna da un intento:

public static final SmsMessage[] getMessagesFromIntent(Intent intent) { 
    Object[] messages = (Object[]) intent.getSerializableExtra("pdus"); 
    if (messages == null || messages.length == 0) { 
     return null; 
    } 

    byte[][] pduObjs = new byte[messages.length][]; 

    for (int i = 0, len = messages.length; i < len; i++) { 
     pduObjs[i] = (byte[]) messages[i]; 
    } 

    byte[][] pdus = new byte[pduObjs.length][]; 
    SmsMessage[] msgs = new SmsMessage[pdus.length]; 
    for (int i = 0, count = pdus.length; i < count; i++) { 
     pdus[i] = pduObjs[i]; 
     msgs[i] = SmsMessage.createFromPdu(pdus[i]); 
    } 

    return msgs; 
} 

credito completa al grande progetto: http://code.google.com/p/android-smspopup/