Learn Android for Free,issues for developers, mobengineers website provide complete solutions for developers issues posts.It also provides online training for android development

Tuesday, March 12, 2013

Reading SMS from Inbox in Android

package com.srinivas;

import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
import android.database.Cursor;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


// get sms from inbox
        Uri uriSMSURI = Uri.parse("content://sms/inbox");
        Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
// 
        String sms = "";
        while (cur.moveToNext()) {
            sms += "" + cur.getString(3) + " : " + cur.getString(2);        
        }
             TextView tv=(TextView)findViewById(R.id.textView1);
      tv.setText(sms);
}
}



Manifest permission

 <uses-permission android:name="android.permission.READ_SMS"/> 

Download source code here 





0 coment�rios:

Post a Comment

20% off

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

NDTV Gadgets360

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts