简体   繁体   中英

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:+'

}

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.

PS - 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.

尝试使用这个,

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

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:+'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM