i want read Sms inbox in android mobile via android application.Any one know this
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" />
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With