AutoLearnApp/app/src/main/java/com/example/auto_learn_app/MainActivity.java
public void checkPermission(String permission, int requestCode)
    {
        Intent intent;
        if (ContextCompat.checkSelfPermission(MainActivity.this, permission)
                == PackageManager.PERMISSION_DENIED) {

            // Requesting the permission
            ActivityCompat.requestPermissions(MainActivity.this, new String[] { permission }, requestCode);
        }
        else {
            switch (requestCode) {
                case CAMERA_PERMISSION_CODE:
                    Toast.makeText(MainActivity.this, "Opening camera", Toast.LENGTH_SHORT).show();
                    intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent,1);

                    break;
                case STORAGE_PERMISSION_CODE:
                    Toast.makeText(MainActivity.this, "Opening gallery", Toast.LENGTH_SHORT).show();
                    intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    if (uploaded_for_model)
                        startActivityForResult(intent,2);
                    else if (uploaded_for_profile)
                        startActivityForResult(intent, 3);
                    break;
            }
        }
    }
// Function to check and request permission.
Function to check and request permission.
Function to check and request permission .
public void checkPermission(String permission, int requestCode)
    {
        Intent intent;
        if (ContextCompat.checkSelfPermission(MainActivity.this, permission)
                == PackageManager.PERMISSION_DENIED) {
            ActivityCompat.requestPermissions(MainActivity.this, new String[] { permission }, requestCode);
        }
        else {
            switch (requestCode) {
                case CAMERA_PERMISSION_CODE:
                    Toast.makeText(MainActivity.this, "Opening camera", Toast.LENGTH_SHORT).show();
                    intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent,1);
                    break;
                case STORAGE_PERMISSION_CODE:
                    Toast.makeText(MainActivity.this, "Opening gallery", Toast.LENGTH_SHORT).show();
                    intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    if (uploaded_for_model)
                        startActivityForResult(intent,2);
                    else if (uploaded_for_profile)
                        startActivityForResult(intent, 3);
                    break;
            }
        }
    }
public void checkPermission ( String permission , int requestCode ) { Intent intent ; if ( ContextCompat . checkSelfPermission ( MainActivity . this , permission ) == PackageManager . PERMISSION_DENIED ) { ActivityCompat . requestPermissions ( MainActivity . this , new String [ ] { permission } , requestCode ) ; } else { switch ( requestCode ) { case CAMERA_PERMISSION_CODE : Toast . makeText ( MainActivity . this , "Opening camera" , Toast . LENGTH_SHORT ) . show ( ) ; intent = new Intent ( MediaStore . ACTION_IMAGE_CAPTURE ) ; startActivityForResult ( intent , 1 ) ; break ; case STORAGE_PERMISSION_CODE : Toast . makeText ( MainActivity . this , "Opening gallery" , Toast . LENGTH_SHORT ) . show ( ) ; intent = new Intent ( Intent . ACTION_PICK , android . provider . MediaStore . Images . Media . EXTERNAL_CONTENT_URI ) ; if ( uploaded_for_model ) startActivityForResult ( intent , 2 ) ; else if ( uploaded_for_profile ) startActivityForResult ( intent , 3 ) ; break ; } } }
Function to check and request permission.
Function to check and request permission .
// Requesting the permission