I have tried to retrieve all information from SMS Inbox/Outbox of my device. But my mobile number i.e. Sender's mobile number does not seem to be stored. I am trying to get this number so that I can capture mobile number from the OUTBOX and allow user to use it to register on my App, considering it to be near accurate mobile number that the user is using on the device. So that they don't have to type the mobile in my app for registration.
Please let me know if there is any way to find mobile number from the SMS INBOX/SENT
Code here:
public void readSMS (Activity MainActivity)
{
Uri inSMSUri = Uri.parse ("content://sms/inbox");
System.out.println ( "the URI :: " + inSMSUri);
Cursor c = MainActivity.getContentResolver().query(inSMSUri, null, null, null, "date desc");
if (c!= null)
{
StringBuilder sb = new StringBuilder ();
while (c.moveToNext ()) {
System.out.println ("content:" + c.getString (c.getColumnIndex ("body")));
for(int i=0; i<c.getColumnCount();i++)
{
System.out.println("SMS:INBOX: c getColumnName(i):: "+c.getColumnName(i) +
" c.getString(i):: "+c.getString(i));
}
}
c.close ();
Uri outSMSUri = Uri.parse ("content://sms/sent");
c = MainActivity.getContentResolver().query(outSMSUri, null, null, null, "date desc");
if (c!= null)
{
while (c.moveToNext ()) {
System.out.println ("content:" + c.getString (c.getColumnIndex ("body")));
for(int i=0; i<c.getColumnCount();i++)
{
System.out.println("SMS:SENT: c getColumnName(i):: "+c.getColumnName(i) +
" c.getString(i):: "+c.getString(i));
}
}
}
}
}
But SENDER Mobile number column NOT found:
SMS INBOX is generating this output:
content:Hello! You are roaming on Vodafone Maharashtra
SMS:INBOX: c getColumnName(i):: _id c.getString(i):: 9
SMS:INBOX: c getColumnName(i):: thread_id c.getString(i):: 3
SMS:INBOX: c getColumnName(i):: address c.getString(i):: VM-VDFONE
SMS:INBOX: c getColumnName(i):: m_size c.getString(i):: 297
SMS:INBOX: c getColumnName(i):: person c.getString(i):: 0
SMS:INBOX: c getColumnName(i):: date c.getString(i):: 1381599923412
SMS:INBOX: c getColumnName(i):: date_sent c.getString(i):: 1381599913000
SMS:INBOX: c getColumnName(i):: protocol c.getString(i):: 0
SMS:INBOX: c getColumnName(i):: read c.getString(i):: 1
SMS:INBOX: c getColumnName(i):: status c.getString(i):: -1
SMS:INBOX: c getColumnName(i):: type c.getString(i):: 1
SMS:INBOX: c getColumnName(i):: reply_path_present c.getString(i):: 0
SMS:INBOX: c getColumnName(i):: subject c.getString(i):: null
SMS:INBOX: c getColumnName(i):: body c.getString(i):: Hello! You are roaming on Vodafone Maharashtra
SMS:INBOX: c getColumnName(i):: service_center c.getString(i):: +919820005556
SMS:INBOX: c getColumnName(i):: locked c.getString(i):: 0
SMS:INBOX: c getColumnName(i):: sim_id c.getString(i):: 1
SMS:INBOX: c getColumnName(i):: error_code c.getString(i):: 0
SMS:INBOX: c getColumnName(i):: seen c.getString(i):: 1
SMS:INBOX: c getColumnName(i):: ipmsg_id c.getString(i):: 0
But SENDER Mobile number column NOT found:
SMS:SENT: c getColumnName(i):: _id c.getString(i):: 1783
SMS:SENT: c getColumnName(i):: thread_id c.getString(i):: 26
SMS:SENT: c getColumnName(i):: address c.getString(i):: 1909
SMS:SENT: c getColumnName(i):: m_size c.getString(i):: null
SMS:SENT: c getColumnName(i):: person c.getString(i):: 0
SMS:SENT: c getColumnName(i):: date c.getString(i):: 1394009796560
SMS:SENT: c getColumnName(i):: error_code c.getString(i):: 0
SMS:SENT: c getColumnName(i):: seen c.getString(i):: 1
SMS:SENT: c getColumnName(i):: ipmsg_id c.getString(i):: 0
SMS:SENT: c getColumnName(i):: m_size c.getString(i):: 21
SMS:SENT: c getColumnName(i):: person c.getString(i):: 0
SMS:SENT: c getColumnName(i):: date c.getString(i):: 1392004530098
SMS:SENT: c getColumnName(i):: date_sent c.getString(i):: 0
SMS:SENT: c getColumnName(i):: protocol c.getString(i):: null
SMS:SENT: c getColumnName(i):: read c.getString(i):: 1
SMS:SENT: c getColumnName(i):: status c.getString(i):: -1
SMS:SENT: c getColumnName(i):: type c.getString(i):: 2
SMS:SENT: c getColumnName(i):: reply_path_present c.getString(i):: null
SMS:SENT: c getColumnName(i):: subject c.getString(i):: null
SMS:SENT: c getColumnName(i):: body c.getString(i):: Take care
SMS:SENT: c getColumnName(i):: service_center c.getString(i):: null
SMS:SENT: c getColumnName(i):: locked c.getString(i):: 0
SMS:SENT: c getColumnName(i):: sim_id c.getString(i):: 1
SMS:SENT: c getColumnName(i):: error_code c.getString(i):: 0
SMS:SENT: c getColumnName(i):: ipmsg_id c.getString(i):: 0