2015-07-02 16 views
12

Kiedy wysyłam sms na telefon komórkowy z Androidem, mogę wybrać wiele kontaktów (patrz A.png), a wiadomość sms będzie jak jeden rekord.Czy w polu adresu będzie przechowywanych wiele numerów telefonów podczas wysyłania wiadomości SMS na wiele numerów telefonu naraz?

Czy sms może być kwerendy za pomocą "content: // sms /"? czy pole "adres" zwróci wiele numerów telefonów?

Dzięki!

A.png

enter image description here

public static List<String> ListDeleteOld(Context myContext, SMSRange mSMSRange, int beforeDays) { 
     List<String> mListSmsID=new ArrayList<String>(); 

     Uri uri=PublicParFun.GetUriBySMSRange(mSMSRange); 

     Date beforeDate=getCurrentBefore(beforeDays); 
     String[] projection = new String[] {"_id","address"}; 
     Cursor cur = myContext.getContentResolver().query(uri, projection, "date<=" + beforeDate.getTime(), null, "date desc"); 


     while(cur.moveToNext()){   
      String s=cur.getString(cur.getColumnIndex("address"));   
     } 
     cur.close(); 

     return mListSmsID; 
    } 



public static Uri GetUriBySMSRange(SMSRange mSMSRange){ 
     Uri uri=null; 

     final String SMS_URI_ALL = "content://sms/"; 
     final String SMS_URI_INBOX = "content://sms/inbox"; 
     final String SMS_URI_SEND = "content://sms/sent"; 
     final String SMS_URI_OUTBOX = "content://sms/outbox"; 
     final String SMS_URI_DRAFT = "content://sms/draft"; 

     switch (mSMSRange){ 
      case All: 
       uri = Uri.parse(SMS_URI_ALL); 
       break; 

      case Inbox: 
       uri = Uri.parse(SMS_URI_INBOX); 
       break; 

      case Sentbox: 
       uri = Uri.parse(SMS_URI_SEND); 
       break; 

      case Outbox: 
       uri = Uri.parse(SMS_URI_OUTBOX); 
       break; 

      case Draft: 
       uri = Uri.parse(SMS_URI_DRAFT); 
       break; 
     } 

     return uri; 
    } 
+0

Gdybym understad, czy chciałbyś, aby uzyskać wszystkie adresy, zwłaszcza Sms było wysłać? – 5er

+0

Więcej pomysłów dla mnie? – HelloCW

+0

Tak, mam nadzieję uzyskać cały adres, gdy sms został wysłany do wielokrotnego kontaktu – HelloCW

Odpowiedz

5

zestaw zmiennych na przykład:

private static final Uri SMS_SENT_URI = Uri.parse("content://sms/sent"); 
private static final String SMS_ORDER = "date DESC"; 
private static final String ADDRESS_COLUMN_NAME = "address"; 
private static final String DATE_COLUMN_NAME = "date"; 
private static final String BODY_COLUMN_NAME = "body"; 
private static final String TYPE_COLUMN_NAME = "type"; 
private static final String ID_COLUMN_NAME = "_id"; 
private static final String SMS_PREFERENCES = "SMS_PREFERENCES"; 

Masz na Kretę SmsObject. Następnie wystarczy przelać kursor Cursor.

Cały kod: (wezwanie checkNewOutgoingSms (kontekst))

private void checkNewOutgoingSms(Context context) { 

    Cursor smsCursor = getSmsCursor(context); 
    List<Sms> smsList = getLastSmsList(smsCursor,context); 
    if (smsList != null && smsList.size() > 0) { 
     ProtectorWSODao mwtProtectorDao = new ProtectorWSODao(); 
     for (Sms sms : smsList) { 
      // 
      // 
      //read sms content 
      // 
      // 
     } 
     Manager.getInstance(context).sendDataToServer(mwtProtectorDao); 
    } 
    smsCursor.close(); 
} 

public static Cursor getSmsCursor(Context context) { 
    return context.getContentResolver().query(SMS_SENT_URI, null, null, null, SMS_ORDER); 
} 

private List<Sms> getLastSmsList(Cursor smsCursor, Context context) { 
    List<Sms> smsList = new ArrayList<Sms>(); 
    final int lastSmsIntercepted = smsStorage.getLastSmsIntercepted(); 
    boolean update = false; 

    if (smsCursor != null) { 
     if (smsCursor.moveToFirst()) { 
      do { 
       Sms smsParsed = parseSms(smsCursor, context); 
       smsList.add(smsParsed); 


      } while (smsCursor.moveToNext()); 
     } 
    } 
    return smsList; 
} 

public static Sms parseSms(Cursor cursor, Context context) { 
    String number = cursor.getString(cursor.getColumnIndex(ADDRESS_COLUMN_NAME)); 
    String date = cursor.getString(cursor.getColumnIndex(DATE_COLUMN_NAME)); 
    String content = cursor.getString(cursor.getColumnIndex(BODY_COLUMN_NAME)); 
    int smsId = cursor.getInt(cursor.getColumnIndex(ID_COLUMN_NAME)); 

    return new Sms(Sms.SEND, smsId, number, date, content); 
} 
+0

że nie wiem, że będziesz musiał spróbować. Czy uruchomiłeś kod? – 5er