Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i read inbox in android mobile?

Tags:

android

i want read Sms inbox in android mobile via android application.Any one know this

like image 217
kannappan Avatar asked Dec 16 '22 15:12

kannappan


2 Answers

Using the content resolver,

  Uri mSmsinboxQueryUri = Uri.parse("content://sms");
    Cursor cursor1 = getContentResolver().query(
            mSmsinboxQueryUri,
            new String[] { "_id", "thread_id", "address", "person", "date",
                    "body", "type" }, null, null, null);
startManagingCursor(cursor1);
    String[] columns = new String[] { "address", "person", "date", "body",
            "type" };
    if (cursor1.getCount() > 0) {
        String count = Integer.toString(cursor1.getCount());
        Log.e("Count",count);
        while (cursor1.moveToNext()) {
            out.write("<message>");
            String address = cursor1.getString(cursor1
                    .getColumnIndex(columns[0]));
            String name = cursor1.getString(cursor1
                    .getColumnIndex(columns[1]));
            String date = cursor1.getString(cursor1
                    .getColumnIndex(columns[2]));
            String msg = cursor1.getString(cursor1
                    .getColumnIndex(columns[3]));
            String type = cursor1.getString(cursor1
                    .getColumnIndex(columns[4]));
}
 }

This will read both inbox and sent items.If you want to read the inbox or sent items alone then you specify it in content resolver.

   Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
   Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");

For reading your SMS you must add uses-permission in androidmanifest.xml,

    <uses-permission android:name="android.permission.READ_SMS" /> 
like image 92
adithi Avatar answered Dec 28 '22 00:12

adithi


using the content

    ArrayList<String> smsList = new ArrayList<String>();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null,null,null);
int indexBody = cursor.getColumnIndex( SmsReceiver.BODY );
int indexAddr = cursor.getColumnIndex( SmsReceiver.ADDRESS );
if ( indexBody < 0 || !cursor.moveToFirst() ) return;
    smsList.clear();
do
{
    String str = "Sender: " + cursor.getString( indexAddr ) + "\n" + cursor.getString( indexBody );
    smsList.add( str );
}
while( cursor.moveToNext() );

User-Permission in AndroidManifest.xml

    <uses-permission android:name="android.permission.READ_SMS" />
like image 44
dickens prabhu Avatar answered Dec 27 '22 23:12

dickens prabhu