0

i wrote the simple code

    ContentResolver contentResolver = this.getContentResolver();

    Uri uriSMSURI = Uri.parse("content://sms/");

    // HERE I GET THE EXCEPTION 
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

    int count = cur.getCount();

I get an exception about Permission Denial in the third line.

How can i get the Permission ? how can i access the messages ?

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • 1
    Really? Two basic questions 40 minutes apart? You should really search and try to get things done before asking. http://stackoverflow.com/questions/8041849/how-can-i-access-to-all-the-message-sms-folder-in-the-phone – blindstuff Nov 07 '11 at 20:44

2 Answers2

3

If you want to read SMS you have to specify the READ_SMS permission in your manifest like below...

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

The default behavior for Android is to exception an application that tries to access facets of the system that it has not explicitly requested access to, this is to protect the user from malicious software.

Quintin Robinson
  • 81,193
  • 14
  • 123
  • 132
0

You need this line in your AndroidManifest.xml. It should be before the <application> tag.

<uses-permission android:name="android.permission.READ_SMS" />
hovanessyan
  • 30,580
  • 6
  • 55
  • 83