我做了一个应用程序,有一个摄像头和GPS的要求,但当我执行时,我得到这个警告几次,不到1秒的时间。
w/activity:一次只能请求一组权限)
有人能告诉我为什么吗?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
mStatusCamera = intent.getStringExtra("camera");
mScannerView = new ZXingScannerView(this) {
@Override
protected IViewFinder createViewFinderView(Context context) {
return new CustomZXingScannerView(context);
}
};
List<BarcodeFormat> formats = new ArrayList<>();
mListaPassageiros = new ArrayList<>();
formats.add(BarcodeFormat.QR_CODE);
setContentView(mScannerView);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
if (!checkPermission()) {
requestPermission();
} else {
executarDepoisDaPermissao();
}
}
}
private boolean checkPermission() {
return (ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(getApplicationContext(), ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(getApplicationContext(), ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
}
public void executarDepoisDaPermissao() {
final BancoController crud = new BancoController(getBaseContext());
mConectado = isNetworkAvailable();
}
根据请求添加了requestpermissio。
private void requestPermission() {
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
if (!checkPermission()) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, ASK_MULTIPLE_PERMISSION_REQUEST_CODE);
}
}
}
我可以那样用吗?
最佳答案
我认为问题是你要求两个位置权限,你应该只要求一个好的位置,这将工作的粗糙和罚款。