Hi my project requires me to work with webview and camera. I implemented codes in HTML which upon pressing a "Choose File" button, the webview will let me choose whether to capture photo using camera or upload files from my file manager. But I don't want the file option, I just want it to launch camera right after I press the button. This is the code where it asks for permission to use my camera and external storage
public void get_file(){
String[] perms = {/*Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, */Manifest.permission.CAMERA};
//Checking for CAMERA Permissions first
//if (ASWP_CAMUPLOAD && check_permission(3)) {
//ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, file_perm);
//Checking for storage permission to write images for upload
if (ASWP_FUPLOAD && ASWP_CAMUPLOAD && !check_permission(2) && !check_permission(3)) {
ActivityCompat.requestPermissions(MainActivity.this, perms, file_perm);
//Checking for WRITE_EXTERNAL_STORAGE permission
} else if (ASWP_FUPLOAD && !check_permission(2)) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, file_perm);
//Checking for CAMERA permissions
} else if (ASWP_CAMUPLOAD && !check_permission(3)) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, file_perm);
}
}
public boolean check_permission(int permission){
switch(permission){
case 1:
return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
case 2:
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
case 3:
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}
return false;
}
And this is the code that I changed
static boolean ASWP_FUPLOAD = false; //upload file from webview
static boolean ASWP_ONLYCAM = true ; //only use camera as input
I changed the upload file from webview option from true to false. But weird thing is, after I changed it to false, pressing the button never worked anymore. What did I do wrong? If I want to use camera only should I remove some of the lines in public void get_file() ? Hoping for some advises, thank you! Edit: I found one code which is ASWP_ONLYCAM that only enables camera as the only input! But I have no idea how to activate it! p.s. please let me know if you need anymore info