简体   繁体   English

无法解析符号 ActivityCompat

[英]Cannot Resolve symbol ActivityCompat

Cannot resolve symbol 'ActivityCompat' I am trying to send SMS through my application.无法解析符号“ActivityCompat” 我正在尝试通过我的应用程序发送短信。 I have added uses permission on AndroidManifest.xml as well我也在 AndroidManifest.xml 上添加了使用权限

ActivityCompat is not resolving help me out. ActivityCompat 没有解决帮助我。

complie Sdk version is 25编译SDK版本是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这是 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 后在这里,请导入

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.如果对哪个新的 androidx 类替换旧的支持库类感到困惑,请参阅androidx 迁移类映射,只需搜索您要替换的类并将其替换为相应的 androidx 类。

PS - I know this doesn't answer this question per se. PS - 我知道这本身并不能回答这个问题。 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,您尚未在项目中添加 support v4 appcompat 库,

ActivityCompat class belongs to v4 support library, check documentation from here ActivityCompat 类属于 v4 支持库,从这里查看文档

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

add following library to your module build.gradle将以下库添加到您的模块 build.gradle

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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