使用方法 checkSelfPermission
时引发了以下异常。应用程序的 targetSDKVersion 为 21。
FATAL EXCEPTION: main Process: app.Rvamd.RecoverAllMyDeletedFile, PID: 3700 java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/app.Rvamd.RecoverAllMyDeletedFile-1/base.apk)
有人对此有想法吗?已为同一仿真器设备中的另一个应用程序正确调用该方法。 除此之外,我能知道电话/模拟器如何选择支持库方法吗(某些应用程序正确调用了方法,而其他应用程序则没有)?
代码如下
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
return;
}
最佳答案
您可能需要将 compileSdkVersion
升级到 23。这是因为从 API 23 开始添加了运行时权限功能。
关于android - 使用方法 checkSelfPermission 时引发运行时异常 (java.lang.NoSuchMethodError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47621641/