App doesn't respond for camera permission
up vote
0
down vote
favorite
This is a part of QR Code scanner app. In the very beginning of the app it asks for camera permission, when i click to allow, app doesn't respond. but from second time, app works correctly. I think the error may be in checking permission. Please help me to find the mistake.
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback()
@Override
public void surfaceCreated(SurfaceHolder holder)
try
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
cameraSource.start(surfaceView.getHolder());
else
ActivityCompat.requestPermissions(MainActivity.this, new
StringManifest.permission.CAMERA, REQUEST_CAMERA_PERMISSION);
catch (IOException e)
e.printStackTrace();
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
@Override
public void surfaceDestroyed(SurfaceHolder holder)
cameraSource.stop();
);
android surfaceview
add a comment |
up vote
0
down vote
favorite
This is a part of QR Code scanner app. In the very beginning of the app it asks for camera permission, when i click to allow, app doesn't respond. but from second time, app works correctly. I think the error may be in checking permission. Please help me to find the mistake.
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback()
@Override
public void surfaceCreated(SurfaceHolder holder)
try
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
cameraSource.start(surfaceView.getHolder());
else
ActivityCompat.requestPermissions(MainActivity.this, new
StringManifest.permission.CAMERA, REQUEST_CAMERA_PERMISSION);
catch (IOException e)
e.printStackTrace();
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
@Override
public void surfaceDestroyed(SurfaceHolder holder)
cameraSource.stop();
);
android surfaceview
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
check my answer, you have to addonRequestPermissionsResult
callback
– Touhidul Islam
Nov 11 at 8:18
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is a part of QR Code scanner app. In the very beginning of the app it asks for camera permission, when i click to allow, app doesn't respond. but from second time, app works correctly. I think the error may be in checking permission. Please help me to find the mistake.
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback()
@Override
public void surfaceCreated(SurfaceHolder holder)
try
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
cameraSource.start(surfaceView.getHolder());
else
ActivityCompat.requestPermissions(MainActivity.this, new
StringManifest.permission.CAMERA, REQUEST_CAMERA_PERMISSION);
catch (IOException e)
e.printStackTrace();
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
@Override
public void surfaceDestroyed(SurfaceHolder holder)
cameraSource.stop();
);
android surfaceview
This is a part of QR Code scanner app. In the very beginning of the app it asks for camera permission, when i click to allow, app doesn't respond. but from second time, app works correctly. I think the error may be in checking permission. Please help me to find the mistake.
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback()
@Override
public void surfaceCreated(SurfaceHolder holder)
try
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
cameraSource.start(surfaceView.getHolder());
else
ActivityCompat.requestPermissions(MainActivity.this, new
StringManifest.permission.CAMERA, REQUEST_CAMERA_PERMISSION);
catch (IOException e)
e.printStackTrace();
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
@Override
public void surfaceDestroyed(SurfaceHolder holder)
cameraSource.stop();
);
android surfaceview
android surfaceview
asked Nov 11 at 6:11
Bikash Adhikari
15
15
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
check my answer, you have to addonRequestPermissionsResult
callback
– Touhidul Islam
Nov 11 at 8:18
add a comment |
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
check my answer, you have to addonRequestPermissionsResult
callback
– Touhidul Islam
Nov 11 at 8:18
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
check my answer, you have to add
onRequestPermissionsResult
callback– Touhidul Islam
Nov 11 at 8:18
check my answer, you have to add
onRequestPermissionsResult
callback– Touhidul Islam
Nov 11 at 8:18
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
When your permission is given/denied, there is a callback method called, named onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
.
The callback returns with the requestCode
which was the code permission was called with first.
All you have to check
The
requestCode
equals to what permission you asked forgrandResult
array is not emptygrantResults[0]
is equal toPackageManager.PERMISSION_GRANTED
Example:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
switch (requestCode)
case MY_PERMISSIONS_REQUEST: // here, MY_PERMISSIONS_REQUEST is the intended request code
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
// permission was granted, yay! Do the task you need to do.
else
// permission denied, boo! Disable the
// functionality that depends on this permission.
return;
// other 'case' lines to check for other
// permissions this app might request
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
When your permission is given/denied, there is a callback method called, named onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
.
The callback returns with the requestCode
which was the code permission was called with first.
All you have to check
The
requestCode
equals to what permission you asked forgrandResult
array is not emptygrantResults[0]
is equal toPackageManager.PERMISSION_GRANTED
Example:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
switch (requestCode)
case MY_PERMISSIONS_REQUEST: // here, MY_PERMISSIONS_REQUEST is the intended request code
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
// permission was granted, yay! Do the task you need to do.
else
// permission denied, boo! Disable the
// functionality that depends on this permission.
return;
// other 'case' lines to check for other
// permissions this app might request
add a comment |
up vote
1
down vote
When your permission is given/denied, there is a callback method called, named onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
.
The callback returns with the requestCode
which was the code permission was called with first.
All you have to check
The
requestCode
equals to what permission you asked forgrandResult
array is not emptygrantResults[0]
is equal toPackageManager.PERMISSION_GRANTED
Example:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
switch (requestCode)
case MY_PERMISSIONS_REQUEST: // here, MY_PERMISSIONS_REQUEST is the intended request code
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
// permission was granted, yay! Do the task you need to do.
else
// permission denied, boo! Disable the
// functionality that depends on this permission.
return;
// other 'case' lines to check for other
// permissions this app might request
add a comment |
up vote
1
down vote
up vote
1
down vote
When your permission is given/denied, there is a callback method called, named onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
.
The callback returns with the requestCode
which was the code permission was called with first.
All you have to check
The
requestCode
equals to what permission you asked forgrandResult
array is not emptygrantResults[0]
is equal toPackageManager.PERMISSION_GRANTED
Example:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
switch (requestCode)
case MY_PERMISSIONS_REQUEST: // here, MY_PERMISSIONS_REQUEST is the intended request code
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
// permission was granted, yay! Do the task you need to do.
else
// permission denied, boo! Disable the
// functionality that depends on this permission.
return;
// other 'case' lines to check for other
// permissions this app might request
When your permission is given/denied, there is a callback method called, named onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
.
The callback returns with the requestCode
which was the code permission was called with first.
All you have to check
The
requestCode
equals to what permission you asked forgrandResult
array is not emptygrantResults[0]
is equal toPackageManager.PERMISSION_GRANTED
Example:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
switch (requestCode)
case MY_PERMISSIONS_REQUEST: // here, MY_PERMISSIONS_REQUEST is the intended request code
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
// permission was granted, yay! Do the task you need to do.
else
// permission denied, boo! Disable the
// functionality that depends on this permission.
return;
// other 'case' lines to check for other
// permissions this app might request
answered Nov 11 at 6:25
Touhidul Islam
360111
360111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246319%2fapp-doesnt-respond-for-camera-permission%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
See this answer stackoverflow.com/a/53246376/7360848 and if it solves the problem, mark it as the accepted answer please :)
– Touhidul Islam
Nov 11 at 7:44
@TouhidulIslam , i'm not getting you. What should i do for my code?
– Bikash Adhikari
Nov 11 at 8:10
check my answer, you have to add
onRequestPermissionsResult
callback– Touhidul Islam
Nov 11 at 8:18