获得W/活动:一次只能请求一组权限 [英] Getting W/Activity: Can request only one set of permissions at a time

查看:664
本文介绍了获得W/活动:一次只能请求一组权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个需要摄像头和GPS的应用程序,但是当我执行该应用程序时,我收到此警告的时间间隔不超过1秒.

I made an app that have a request for camera and GPS, but when I execute I am getting this warning several times with less than 1 second of each other.

活动:一次只能获得一组权限

W/Activity: Can reqeust only one set of permissions at a time)

有人可以告诉我为什么吗?

Can some one tell me why?

@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.

Added RequestPermissio as requested.

 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);
        }
    }

}

我可以那样使用吗?

推荐答案

我认为问题是您需要两个位置权限,您应该只请求适用于粗略和精细位置的精细位置.

I think problem is that you ask for two location permissions, you should ask only for fine location which will work for both coarse and fine.

这篇关于获得W/活动:一次只能请求一组权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆