• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android permissoin denial on READ_SMS, added permission AndroidManifest file

vmgunda

Lurker
Sep 21, 2015
5
1
Configuration:

Studio 1.3
API 23
I am learning Android and started working on SMS read a simple project. i have added the permissions in the SMS_READ in the AndroidManifest.xml. Still when run emulator it throwing error permission denial for SMS_READ. I am not sure that emulator problem or API 23 level permission change?. I have not tried in real phone device but tried in emulator

Error:

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=1900, uid=10058 requires android.permission.READ_SMS, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1599)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:491)
at android.content.ContentResolver.query(ContentResolver.java:434)
at com.example.gunda.mysmsreadapp.MainActivity.fetchInbox(MainActivity.java:68)
at com.example.gunda.mysmsreadapp.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Here is the manifest xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gunda.mysmsreadapp" >
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:theme="@Style/AppTheme" >
android:exported="true"

<activity
android:name=".MainActivity"
android:label="@String/app_name" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--<action android:name="android.provider.Telephony.READ_SMS" />-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Code:
Uri uriSms =Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(uriSms,newString[
 
Hi,

Using API 23 on an emulator running Android M, the new permissions policy apply : you have to call the requestPermissions method (from Activity) for every permission that exposes user personnal data. (that will prompt the user to allow the requested pemission at runtime). Note that the user can refuse to grant the permission, so you have to manage this case.

See https://developer.android.com/preview/features/runtime-permissions.html for further details.

Cheers,
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones