I'm attempting to read the sms content, but failing with a PermissionDenial exception. I believe I have the syntax correct, but may possibly be missing necessary elements from my manifest other than the permission (I created it uses Android Studio's New Project wizard).
My AndroidManifest.xml file is (Note that I HAVE moved the uses-permission above and below the application in the xml):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mytests.testapp" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_SMS" />
</manifest>
and the function that is reading the sms messages is:
public void loadMessages(){
Uri allMessages = Telephony.Sms.CONTENT_URI;
Cursor cursor = this.getContentResolver().query(allMessages, null, null, null, null);
while (cursor.moveToNext()){
for (int i = 0; i < cursor.getColumnCount(); i++){
Log.d(cursor.getColumnName(i) + "", cursor.getString(i) + "");
}
Log.d("one row finished", "*********");
}
}