我的设备棉花糖,所以我应该添加获取权限代码。 我的app相机预览应用。 获得权限代码,而不是活动。
所以,我不知道如何在非活动
上使用onRequestPermissionsResult
我的来源
public class WebClient {
public void readyCamera() {
// camera releation work.
}
private void setCamera() {
Activity activity = MainActivity.getMainActivity(); //get Activity
if (Build.VERSION.SDK_INT >= M) { //over marshmallow
if (ContextCompat.checkSelfPermission(activity , Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) { //no permission
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA)) {
ActivityCompat.requestPermissions(activity, new String[] {Manifest.permission.CAMERA}, 1000);
} else {
ActivityCompat.requeestPermissions(activity, new String[] {Manifest.permission.CAMERA}, 1000);
}
} else {
readyCamera();
}
} readyCamera();
}
@Override
private void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 1000:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
readyCamera();
} else {
}
}
}
如何在非活动中使用onRequestPermissionsResult
方法?
感谢:)