Showing posts with label Camera Permission programatically. Show all posts
Showing posts with label Camera Permission programatically. Show all posts

Tuesday 23 April 2019

Camera Permission programatically

In newer version android needs types of permission that user need to ask user to allow , here i will show you one of the Camera permission that how we can use in android programatically.

First you have to add permission in Menifest.xml file

<uses-permission android:name="android.permission.CAMERA" />

Below code you have to add where you want to ask for permission for Camera.

ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},

1);

Then the below code you have to put.

@Overridepublic void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1: {

            // If request is cancelled, the result are empty.            
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted,  Do the code
               
            } else {

                // permission denied, 
                Toast.makeText(MainActivity.this, 
"Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
            }
            return;
        }

    }
}

Thats it ,from using this code you done for Camera Permission.

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...