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

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

I made an app that have a request for camera and GPS, but whem I execute I am getting this Warm several times with less them 1 sec 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(); } 

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

Can I use that way?

回答1:

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



回答2:

So, I can't see your requestPermission() method from here, but you shouldn't send multiple permission requests in the same time.

You should make ONE request with ALL the permissions.

int permissions_code = 42;  String[] permissions = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION};  if(!hasPermissions(this, permissions)){     ActivityCompat.requestPermissions(this, permissions, permissions_code); } 


回答3:

For anyone else stumbling upon this issue..You need to request permissions serially,like this:

onRequestPermissionResult(){ case permission1:  if (permission1.aquired()){ ....//do what you do  requestPermission2();  }  case permission2:  if (permission2.aquired()){ ....//do what you do  requestPermission3();  }  } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!