我在请求marshmallow权限时遇到问题,我有这个功能
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
Toast.makeText(this, "GPS permission allows us to access location data. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_REQUEST_CODE);
}
}
和我的进口
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
我在build.gradle
中有这种依赖关系dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.19.0'
compile 'com.parse:parsefacebookutils-v4-android:1.10.4@aar'
compile 'com.parse:parse-android:1.13.1'
我得到了
"无法解析方法 " ActivityCompat.shouldShowRequestPermissionRationale"并在 " ActivityCompat.requestPermissions"
关于可能发生的事情的任何想法?
答案 0 :(得分:0)
这可能会有所帮助。它显示了如何检查是否已授予权限,并请求新的权限(在这种情况下,它是记录音频和写入外部存储)
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) + ContextCompat
.checkSelfPermission(MainActivity.this,
Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale
(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ||
ActivityCompat.shouldShowRequestPermissionRationale
(MainActivity.this, Manifest.permission.RECORD_AUDIO)) {
mToggleButton.setChecked(false);
Snackbar.make(findViewById(android.R.id.content), R.string.label_permissions,
Snackbar.LENGTH_INDEFINITE).setAction("ENABLE",
new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission
.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO},
REQUEST_PERMISSIONS);
}
}).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission
.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO},
REQUEST_PERMISSIONS);
}
} else {
(function here)
}
答案 1 :(得分:0)
我创建了一个解决方案,更改了导入
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
到
compile('fr.avianey.com.viewpagerindicator:library:2.4.1') {
exclude group: 'com.google.android', module: 'support-v4'
}
它解决了一切