2012-02-03 5 views
10

Come so che Nokia e altri telefoni (come iPhone) sono in grado di inviare e ricevere SMS di classe 0, è possibile per Android? Android ha l'API?Classe 0 SMS (flash SMS) su Android

Che cos'è Flash SMS?

Flash SMS è un SMS che viene visualizzato sullo schermo del telefono immediatamente all'arrivo.

A meno che non si scelga di salvare il messaggio flash, questo scompare dopo la navigazione e non verrà salvato nella casella di posta in arrivo.

Se più messaggi flash vengono inviati a un telefono, verrà visualizzato solo l'ultimo messaggio e tutti i precedenti verranno sovrascritti.

Classe 0: indica che questo messaggio deve essere visualizzato immediatamente su MS e un rapporto di consegna messaggio deve essere rinviato allo SC. Il messaggio non deve essere salvato nel MS o sulla scheda SIM (a meno che non venga selezionato dall'utente mobile).

+2

Ehi, hai idea di cosa significano le altre tre classi?Ho cercato per circa due ore, ma non sono in grado di trovare alcuna cosa. – harshit

risposta

8

Per radicata Android è possibile bypassare un'API e inviare classe 0 SMS. C'è un progetto su Git Hub chiamato ZeroSMS:

ZeroSMS è un concetto proof-of-dimostrazione di un modo per inviare classe 0 SMS su Android> = 2.3.

Nota: questo funziona solo su versioni 2.2 -> 4.1.2, il metodo sendRawPdu è stato rimosso, quindi sarà necessario trovare un nuovo modo per fare questo.

+0

Nice. Selezionata come risposta – xDragonZ

+1

Funziona solo con le ROM CyanogenMod, poiché richiede la firma dell'APK con i certificati CyanogenMod. – chuacw

+0

Ho provato a installare l'app Zero Sms sul mio telefono rooted, ma l'installazione non è riuscita per entrambi gli apk firmati e normali. Questo Zero Sms funziona solo con CyanogenMod? Ho bisogno di questo per la versione di kitkat – Viral

1

Sì e no. È facilmente possibile? No. È tecnicamente possibile con le buffonate (leggi: riflessione)? Usually.

6

E 'stato possibile inviare SMS Flash (che è il termine per SMS di classe 0) prima di Android 2.2. Google ha rimosso l'API sendRawPdu, quindi anche se si utilizzava il reflection, non sarebbe possibile farlo.

Ecco come ho fatto in precedenza (questo è stato testato su Android 1.6 e lavorato)

private void sendSms(String phone, String sms) { 
    if ((phone == null) || (sms == null) || (phone.length() == 0) 
      || (sms.length() == 0)) { 
     String message = "Phone or message empty!!!"; 
     Toast notification = Toast.makeText(getBaseContext(), message, 
       Toast.LENGTH_SHORT); 
     notification.show(); 
     return; 
    } 

    // SecurityManager oldSM = System.getSecurityManager(); 
    // MySecurityManager newSM = new MySecurityManager(); 
    // System.setSecurityManager(newSM); 

    // ServiceManager.getService("isms") 
    // ServiceManager.getService("isms"); 

    SmsManager m = SmsManager.getDefault(); 
    PendingIntent sentIntent = PendingIntent 
      .getBroadcast(this, 0, new Intent(
        MessageStatusReceiver_MESSAGE_STATUS_RECEIVED_ACTION), 
        0); 

    PendingIntent deliveryIntent = PendingIntent.getBroadcast(this, 0, 
      new Intent(SmsReceiverService_MESSAGE_SENT_ACTION), 0); 

    // String sms = "Message self-destroyed!!!"; 
    // String phone = "93634096"; 

    long NOW = System.currentTimeMillis(); 
    String time = String.valueOf(NOW); 

    // // m.sendTextMessage(phone, null, sms, sentIntent, deliveryIntent); 
    // working // m.sendTextMessage(phone, null, sms, null, null); 
    byte[] bb = new byte[1]; 
    Method m2 = null; 
    try { 
     m2 = SmsManager.class.getDeclaredMethod("sendRawPdu", 
       bb.getClass(), bb.getClass(), PendingIntent.class, 
       PendingIntent.class); 
    } catch (SecurityException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (NoSuchMethodException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    // send message 

    SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(null, phone, sms, 
      false); 

    // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=telephony/java/android/telephony/gsm/SmsMessage.java;h=9ccfa90d2e24e5caea26c1deac641b3c31ae56d4;hb=c883b143ba2b8bfe2f2033d00dee9ff733f1b59c 

    boolean submitted = false; 
    try { 
     byte[] encodedMessage = pdus.encodedMessage; 
     // byte[0] = mtiByte 
     // byte[1] = TP Message Reference 
     // byte[2] = length of source phone 
     // byte[3..length] = phone 
     // protocol identifier 
     int msgLen = encodedMessage[2]/2; 
     // +2 -> length of source phone 
     // +2 -> for 91 after the length 
     // +1 -> TP PID 
     int indexTPDCS = msgLen + 5; 
     byte TPDCS = encodedMessage[indexTPDCS]; 
     // System.out.println(TPDCS); 
     System.out.println(getHexString(encodedMessage)); 
     byte[] changedMessage = encodedMessage.clone(); 
     // Set bit 4 to 1 using OR (|), indicating there is a message class 
     // Set bit 0 and 1 to 0 using AND (&), indicating class 0 
     byte newTPDCS = (byte) ((TPDCS | 0x10) & 0xFC); // Flash SMS 
     changedMessage[indexTPDCS] = newTPDCS; // Class 0 
     System.out.println(getHexString(changedMessage)); 
     // Log.d(SmsScheduler_TAG, getHexString(changedMessage)); 
     boolean send = true; 
     if (send) { 
      m2.invoke(m, pdus.encodedScAddress, changedMessage, null, null); 

      // sendSMS(HexDump.bytesToHexString(pdus.encodedScAddress), 
      // HexDump.bytesToHexString(changedMessage), null); 

      String message = "Flash SMS sent to " + phone 
        + " successfully!"; 
      Toast notification = Toast.makeText(getBaseContext(), message, 
        Toast.LENGTH_SHORT); 
      notification.show(); 
      Log.d(SmsScheduler_TAG, message); 
      submitted = true; 
     } 
    } catch (IllegalArgumentException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (UnsupportedEncodingException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IllegalAccessException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (InvocationTargetException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

      // not essential, saves the SMS sent. 
    if (submitted) { 
     ContentValues values = new ContentValues(); 
     values.put(ADDRESS, phone); 
     values.put(DATE, time); 
     values.put(READ, 0); 
     values.put(STATUS, -1); 
     values.put(TYPE, MESSAGE_TYPE_SENT); 
     values.put(BODY, sms); 

     Uri inserted = getContentResolver().insert(
       Uri.parse("content://sms"), values); 
    } 

    // System.setSecurityManager(oldSM); 

} 
+0

Ok, selezionerò questo come ans dal momento che non funzionerà dopo Android 2.2 – xDragonZ

2

Scrool La risposta è corretta, https://stackoverflow.com/a/12873325/3082310, poiché ZeroSMS invia SMS flash; tuttavia, è una prova di concetto e supporta solo gli SMS con codifica a 7 bit.

Per codifica appropriata sembra v'è la necessità di modificare il codice e aggiungere if-then o passa-istruzioni case: Per la codifica 7-bit, come in inglese

uso (byte)0xF0

per 16 codifica bit, UCS-2 codifica

uso (byte) 0x18

In caso contrario, i personaggi appaiono spazzatura se si immette lingua non supportata.