Faraz Naeem
Faraz Naeem

Reputation: 35

Cannot Resolve symbol ActivityCompat

Cannot resolve symbol 'ActivityCompat' I am trying to send SMS through my application. I have added uses permission on AndroidManifest.xml as well

ActivityCompat is not resolving help me out.

complie Sdk version is 25

    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, message, null, null);
        if (ContextCompat.checkSelfPermission(sendSMS2.this, Manifest.permission.SEND_SMS)
                != PackageManager.PERMISSION_GRANTED) {
            // Permission is not granted
            // Ask for permision
            ActivityCompat.requestPermissions(this,new String[] { Manifest.permission.SEND_SMS}, 1);
        }

here is the build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.example.somme.testproj2"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:appcompat-v7:+'

}

Upvotes: 3

Views: 11748

Answers (3)

Derryl Thomas
Derryl Thomas

Reputation: 1568

In case anyone is here after shifting to androidx, import

androidx.core.app.ActivityCompat;

instead of

android.support.v4.app.ActivityCompat;

In case of confusions regarding which new androidx class replaces the old support library class, refer this androidx migration class mapping and just search for the class you'd like to replace and replace it with the corresponding androidx class.

P.S. - I know this doesn't answer this question per se. Just leaving it here for anyone else who might land here because of the question title.

Upvotes: 16

Awais Tariq
Awais Tariq

Reputation: 283

Try Using this,

compile 'com.android.support:support-compat:25.0.0'

Upvotes: 1

karan
karan

Reputation: 8853

You have not added support v4 appcompat library in your project,

ActivityCompat class belongs to v4 support library, check documentation from here

https://developer.android.com/reference/android/support/v4/app/ActivityCompat

add following library to your module build.gradle

compile 'com.android.support:support-compat:+'

Upvotes: 1

Related Questions