无法解析符号“ActivityCompat” 我正在尝试通过我的应用程序发送短信。 我还在 AndroidManifest.xml 上添加了使用权限
ActivityCompat 无法解析,请帮帮我。
编译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);
}
这是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:+'
}
最佳答案
万一有人在转移到 androidx 后在这里, 导入
androidx.core.app.ActivityCompat;
而不是
android.support.v4.app.ActivityCompat;
如果对哪个新的 androidx 类替换旧的支持库类感到困惑,请参阅 this androidx 迁移类映射,只需搜索您要替换的类并将其替换为相应的 androidx 类即可。
附注- 我知道这本身并不能回答这个问题。只是把它留在这里给其他可能因为问题标题而来到这里的人。
关于android - 无法解析符号 ActivityCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52661886/