2017-10-06 6 views
0

J'ai un arraylist qui ont un certain nombre de contact et je veux passer cette arraylist à l'adresse. Pour qu'il reçoive tous les messages des numéros sélectionnés qui sont dans Arraylist. Merci d'avance.Comment lire tous les SMS de la boîte de réception par plus d'un expéditeur, mais pas par tous les expéditeurs dans Android?

StringBuilder smsBuilder = new StringBuilder(); 
    final String SMS_URI_INBOX = "content://sms/inbox"; 
    final String SMS_URI_ALL = "content://sms/"; 

    Uri uri = Uri.parse(SMS_URI_INBOX); 
    String[] projection = new String[] { "_id", "address", "person", "body", "date", "type" }; 

    Cursor cur = getContentResolver().query(uri, projection, "address='"+list+"'" , null, "date desc"); 

    if (cur.moveToFirst()) 
    { 
     int index_Address = cur.getColumnIndex("address"); 
     int index_Person = cur.getColumnIndex("person"); 
     int index_Body = cur.getColumnIndex("body"); 
     int index_Date = cur.getColumnIndex("date"); 
     int index_Type = cur.getColumnIndex("type"); 
     do 
     { 
      String strAddress = cur.getString(index_Address); 
      int intPerson = cur.getInt(index_Person); 
      String strbody = cur.getString(index_Body); 
      long longDate = cur.getLong(index_Date); 
      int int_Type = cur.getInt(index_Type); 


      String str = "SMS From: " + cur.getString(index_Address) + 
        "\n" + cur.getString(index_Body) + "\n"; 
      arrayAdapter.add(str); 

      smsBuilder.append("[ "); 
      smsBuilder.append(strAddress + ", "); 
      smsBuilder.append(intPerson + ", "); 
      smsBuilder.append(strbody + ", "); 
      smsBuilder.append(longDate + ", "); 
      smsBuilder.append(int_Type); 
      smsBuilder.append(" ]\n\n"); 
     } while (cur.moveToNext()); 

     if (!cur.isClosed()) 
     { 
      cur.close(); 
      cur = null; 
     } 
    } 
    else 
    { 
     smsBuilder.append("no result!"); 
    } // end if 
} 
+0

Où est ce 'ArrayList' des numéros dans votre code? – pleft

+0

Possible copie de [Obtenir SMS d'un numéro de téléphone spécifique] (https://stackoverflow.com/questions/14721772/get-sms-of-specific-phone-number) – pleft

+0

Non, je demande comment passer plus d'un contact numéro à adresser? @pleft –

Répondre

0
 int argcount = MOBILENUMBER.size(); // number of IN arguments i.e More than one Mobile number for which you want read SMS 

    // String[] args = new String[]{ 1, 2 }; 
    StringBuilder inList = new StringBuilder(argcount * list.length); 
    for (int i = 0; i < argcount; i++) 
    { 
     if(i > 0) 
     { 
      inList.append(","); 
     } 
     inList.append("?");//This will generate Number of "? " to match our item in array list 
    } 
    Cursor cur = getContentResolver().query(uri, projection, "address IN (" + inList.toString() + ")" , list, "date DESC ");