Reputation: 1091
I am just invoking the run time camera permission dialog to enable the camera permission if it was disabled.
getting three problems in that:
1) Method does not override or implement a method from super type for the below method
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_CAMERA: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related 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
}
}
2) even if the camera permission is disabled its giving as '0' which is permission granted rite?
i don't know why its giving '0' when permission disabled.
Device : Samsung Galaxy s6
int MY_PERMISSIONS_REQUEST_Camera=101;
if (mActivity.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (mActivity.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
mActivity.requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_Camera);
// MY_PERMISSIONS_REQUEST_Camera is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
3) If i enable the permission during run time, the app gets restarted which i doesn't want.
Can anyone please help me for the above three problems...
Upvotes: 0
Views: 269
Reputation: 23881
Check your request code:
mActivity.requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_Camera);
it should be:
mActivity.requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CAMERA);
Upvotes: 0