Issue
Can you please tell me how can I get the response of this function?
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
Solution
That code work for me..
Step 1: write down code in your Activity
- create callback of permission
requestPermissionLauncher
- create that callback globaly in your
Activity
private ActivityResultLauncher<String> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
afterPermission(); // here you got success of permission
} else {
Toast.makeText(this, "Please allow permission", Toast.LENGTH_SHORT).show();
}
});
Step 2: lunch permission in your Activity
//CHECK_PERMISSION_BUTTON.setOnClickListener((view -> {
requestPermissionLauncher.launch(Manifest.permission.YOUR_PERMISSION);
//}));
Answered By - Urvish Shiroya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.