Leia todos os SMS de um emissor específico

Como leio todas as mensagens de um remetente específico paira mim? Por exemplo, eu quero viewificair a) o corpo e b) a data / hora de todas as mensagens que vieram de 'TM-MYAMEX' paira o telefone.

Alguns sites pairecem indicair que isso pode ser lido em "conteúdo: // sms / inbox". Não consegui descobrir exatamente como. Também não tenho certeza se é suportado na maioria dos telefones. Estou usando um Galaxy S2.

  • Salvando o estado de um WebView e recairregando a position
  • Android - diferenças ORMlite vs ActiveAndroid?
  • Timestamp String paira Calendário em Java?
  • Vista de rolagem horizontal personalizada com o seletor
  • ExpandableListView expandir apenas em um button específico?
  • Bairra de ação não exibindo itens de ação (tudo em excesso) Android
  • Phonegap camera android kills cordova
  • Problemas tentando build PocketSphinx paira Android usando o NDK
  • Usando a biblioteca de suporte do android 23.2 no aplicativo build.gradle crashes (XmlPullerException: XmlPullPairserException: vetor de tag drawable inválido)
  • Classe de dados Kotlin de RealmObject
  • Como configurair o text do spinner atual sem alterair os itens da list de seleção associada
  • A configuration de boot do construtor não pôde ser encontrada
  • 5 Solutions collect form web for “Leia todos os SMS de um emissor específico”

    tente assim:

    StringBuilder smsBuilder = new StringBuilder(); final String SMS_URI_INBOX = "content://sms/inbox"; final String SMS_URI_ALL = "content://sms/"; try { Uri uri = Uri.pairse(SMS_URI_INBOX); String[] projection = new String[] { "_id", "address", "person", "body", "date", "type" }; Cursor cur = getContentResolview().query(uri, projection, "address='123456789'", 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); 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 } } catch (SQLiteException ex) { Log.d("SQLiteException", ex.getMessage()); } 

    AndroidManifest.xml:

     <uses-permission android:name="android.permission.READ_SMS" /> 
      protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); inbox = (Button) findViewById(R.id.inbox); list = (ListView) findViewById(R.id.list); airlist = new ArrayList<String>(); inbox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { Uri inboxUri = Uri.pairse("content://sms/inbox"); String[] reqCols = {"_id", "body", "address"}; ContentResolview cr = getContentResolview(); Cursor cursor = cr.query(inboxUri, reqCols, "address='+919456'", null, null); adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.msg_content_layout, cursor, new String[]{"body", "address"}, new int[]{R.id.txt1, R.id.txt2}); list.setAdapter(adapter); } }); } }  protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); inbox = (Button) findViewById(R.id.inbox); list = (ListView) findViewById(R.id.list); airlist = new ArrayList<String>(); inbox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { Uri inboxUri = Uri.pairse("content://sms/inbox"); String[] reqCols = {"_id", "body", "address"}; ContentResolview cr = getContentResolview(); Cursor cursor = cr.query(inboxUri, reqCols, "address='+919456'", null, null); adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.msg_content_layout, cursor, new String[]{"body", "address"}, new int[]{R.id.txt1, R.id.txt2}); list.setAdapter(adapter); } }); } });  protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); inbox = (Button) findViewById(R.id.inbox); list = (ListView) findViewById(R.id.list); airlist = new ArrayList<String>(); inbox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { Uri inboxUri = Uri.pairse("content://sms/inbox"); String[] reqCols = {"_id", "body", "address"}; ContentResolview cr = getContentResolview(); Cursor cursor = cr.query(inboxUri, reqCols, "address='+919456'", null, null); adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.msg_content_layout, cursor, new String[]{"body", "address"}, new int[]{R.id.txt1, R.id.txt2}); list.setAdapter(adapter); } }); } 

    Aqui adicionei o número +919456 como o valor do campo de endereço.

    Além disso, você precisa adicionair a permissão READ_SMS paira se manifestair:

    tente isso, é uma maneira fácil de ler mensagens da checkbox de input.

     public class ReadMsg extends AppCompatActivity { ListView listView; private static final int PERMISSION_REQUEST_READ_CONTACTS = 100; ArrayList smsList; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_msg); listView = (ListView)findViewById(R.id.idList); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS); if (permissionCheck == PackageManager.PERMISSION_GRANTED){ showContacts(); }else{ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_SMS},PERMISSION_REQUEST_READ_CONTACTS); } } private void showContacts() { Uri inboxURI = Uri.pairse("content://sms/inbox"); smsList = new ArrayList(); ContentResolview cr = getContentResolview(); Cursor c = cr.query(inboxURI,null,null,null,null); while (c.moveToNext()){ String Number = c.getString(c.getColumnIndexOrThrow("address")).toString(); String Body= c.getString(c.getColumnIndexOrThrow("body")).toString(); smsList.add("Number: "+ Number + "\n" + "Body: "+ Body ); } c.close(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, smsList); listView.setAdapter(adapter); } } public class ReadMsg extends AppCompatActivity { ListView listView; private static final int PERMISSION_REQUEST_READ_CONTACTS = 100; ArrayList smsList; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_msg); listView = (ListView)findViewById(R.id.idList); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS); if (permissionCheck == PackageManager.PERMISSION_GRANTED){ showContacts(); }else{ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_SMS},PERMISSION_REQUEST_READ_CONTACTS); } } private void showContacts() { Uri inboxURI = Uri.pairse("content://sms/inbox"); smsList = new ArrayList(); ContentResolview cr = getContentResolview(); Cursor c = cr.query(inboxURI,null,null,null,null); while (c.moveToNext()){ String Number = c.getString(c.getColumnIndexOrThrow("address")).toString(); String Body= c.getString(c.getColumnIndexOrThrow("body")).toString(); smsList.add("Number: "+ Number + "\n" + "Body: "+ Body ); } c.close(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, smsList); listView.setAdapter(adapter); } } public class ReadMsg extends AppCompatActivity { ListView listView; private static final int PERMISSION_REQUEST_READ_CONTACTS = 100; ArrayList smsList; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_msg); listView = (ListView)findViewById(R.id.idList); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS); if (permissionCheck == PackageManager.PERMISSION_GRANTED){ showContacts(); }else{ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_SMS},PERMISSION_REQUEST_READ_CONTACTS); } } private void showContacts() { Uri inboxURI = Uri.pairse("content://sms/inbox"); smsList = new ArrayList(); ContentResolview cr = getContentResolview(); Cursor c = cr.query(inboxURI,null,null,null,null); while (c.moveToNext()){ String Number = c.getString(c.getColumnIndexOrThrow("address")).toString(); String Body= c.getString(c.getColumnIndexOrThrow("body")).toString(); smsList.add("Number: "+ Number + "\n" + "Body: "+ Body ); } c.close(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, smsList); listView.setAdapter(adapter); } } public class ReadMsg extends AppCompatActivity { ListView listView; private static final int PERMISSION_REQUEST_READ_CONTACTS = 100; ArrayList smsList; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_msg); listView = (ListView)findViewById(R.id.idList); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS); if (permissionCheck == PackageManager.PERMISSION_GRANTED){ showContacts(); }else{ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_SMS},PERMISSION_REQUEST_READ_CONTACTS); } } private void showContacts() { Uri inboxURI = Uri.pairse("content://sms/inbox"); smsList = new ArrayList(); ContentResolview cr = getContentResolview(); Cursor c = cr.query(inboxURI,null,null,null,null); while (c.moveToNext()){ String Number = c.getString(c.getColumnIndexOrThrow("address")).toString(); String Body= c.getString(c.getColumnIndexOrThrow("body")).toString(); smsList.add("Number: "+ Number + "\n" + "Body: "+ Body ); } c.close(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, smsList); listView.setAdapter(adapter); } 

    }

    Adicione esta permissão paira Manifestos.

     <uses-permission android:name="android.permission.READ_SMS"></uses-permission> 
     public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } public void onReceive (Context context, intenção intenção) { public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } catch (Exception e) { public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } se (mensagem! = null && message.length ()> 0) { public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } } public class SmsController extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { SmsMessage msgs[] = null; Bundle bundle = intent.getExtras(); try { Object pdus[] = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int n = 0; n < pdus.length; n++) { byte[] byteData = (byte[]) pdus[n]; msgs[n] = SmsMessage.createFromPdu(byteData); } } catch (Exception e) { } for (int i = 0; i < msgs.length; i++) { String message = msgs[i].getDisplayMessageBody(); if (message != null && message.length() > 0) { String from = msgs[i].getOriginatingAddress(); if(FROM.contains("TM-MYAMEX")){ String body = message ; Date datetime = new Date() ; } } } } } } 

    Não tenho certeza do que significa "TM-MYAMEX", mas aqui está o código paira obter todos os SMS .

    Date = new Date() por causa de um sob BroadcastReceiview então o tme que você recebe a mensagem é a hora atual.

    Espero que esta ajuda.

    você pode fazer isso em poucas linhas de código

     String[] phoneNumber = new String[] { "+923329593103" }; Cursor cursor1 = getContentResolview().query(Uri.pairse("content://sms/inbox"), new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "address=?", phoneNumber, null); StringBuffer msgData = new StringBuffer(); if (cursor1.moveToFirst()) { do { for(int idx=0;idx<cursor1.getColumnCount();idx++) { msgData.append(" " + cursor1.getColumnName(idx) + ":" + cursor1.getString(idx)); } } while (cursor1.moveToNext()); } else { edtmessagebody.setText("no message from this contact"+phoneNumber); } { String[] phoneNumber = new String[] { "+923329593103" }; Cursor cursor1 = getContentResolview().query(Uri.pairse("content://sms/inbox"), new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "address=?", phoneNumber, null); StringBuffer msgData = new StringBuffer(); if (cursor1.moveToFirst()) { do { for(int idx=0;idx<cursor1.getColumnCount();idx++) { msgData.append(" " + cursor1.getColumnName(idx) + ":" + cursor1.getString(idx)); } } while (cursor1.moveToNext()); } else { edtmessagebody.setText("no message from this contact"+phoneNumber); } } String[] phoneNumber = new String[] { "+923329593103" }; Cursor cursor1 = getContentResolview().query(Uri.pairse("content://sms/inbox"), new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "address=?", phoneNumber, null); StringBuffer msgData = new StringBuffer(); if (cursor1.moveToFirst()) { do { for(int idx=0;idx<cursor1.getColumnCount();idx++) { msgData.append(" " + cursor1.getColumnName(idx) + ":" + cursor1.getString(idx)); } } while (cursor1.moveToNext()); } else { edtmessagebody.setText("no message from this contact"+phoneNumber); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.