App doesn't respond for camera permission
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 |
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 |
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
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 |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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
1,0251314
1,0251314
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