geniye
geniye

Reputation: 105

Android Studio - Permission Denial, requires android.permission.RECEIVE_SMS error

So, I have been scraping every single doc page and StackOverflow page to find an answer for this and I have literally found nothing. Today I have been making an app that needs to read all SMS's I receive and search for a specific phrase.

However, I realized I needed the RECEIVE_SMS permission, which I did - permission denied.

So I added the capability for the app to ask for permissions from the user, given the SDK is over 22 - permission denied.

I have plugged in every little thing I have found throughout these forums and nothing seems to be working, no matter what I do it still says permission denied and I can't read the SMS messages.

If anyone could help it would be much appreciated because at the moment it's beginning to look like the app is a lost cause.

This is what the error looks like:

2019-10-30 14:50:53.097 1403-1413/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x19000010 (has extras) } to ProcessRecord{cb5e9afd0 1159:com.samsung.android.email.provider/u0a68} (pid=1159, uid=10068) requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

Here is the MainActivity file:

package app.genyie.tnat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private static final int PERMISSIONS_REQUEST_RECEIVE_SMS = 0;

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

        requestPermissions(Manifest.permission.RECEIVE_SMS, PERMISSIONS_REQUEST_RECEIVE_SMS);
    }

    private void requestPermissions(String permission, int requestCode) {
        // Here, thisActivity is the current activity
        if (ContextCompat.checkSelfPermission(this, permission)
                != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                Toast.makeText(this, "Granting permission is necessary!", Toast.LENGTH_LONG).show();

            } else {

                // No explanation needed, we can request the permission.

                ActivityCompat.requestPermissions(this,
                        new String[]{permission},
                        requestCode);

                // requestCode is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSIONS_REQUEST_RECEIVE_SMS: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.



                } else {

                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.


                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }
}

And here is the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="app.genyie.tnat">

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-sdk android:minSdkVersion="26"/>

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".BGServ"/>

        <receiver
            android:name=".SmsListener">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

If you need any other files let me know, thank you for your time!

Upvotes: 0

Views: 2563

Answers (1)

Dinesh
Dinesh

Reputation: 988

Read SMS permission is officially taken off due to security concerns. If you still need it, you would need to apply for whitelisting.

https://proandroiddev.com/no-more-sms-call-log-permissions-now-what-9b8226de7827

Upvotes: 1

Related Questions