Skip to content

Commit

Permalink
fix(android): avoid crash on input file capture (#3715)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 22, 2020
1 parent 59c322b commit f502a99
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
Expand Down Expand Up @@ -331,9 +332,8 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
}

private boolean isMediaCaptureSupported() {
Plugin camera = bridge.getPlugin("Camera").getInstance();
boolean isSupported = camera.hasPermission(Manifest.permission.CAMERA) || !camera.hasDefinedPermission(Manifest.permission.CAMERA);
return isSupported;
String[] permissions = { Manifest.permission.CAMERA };
return hasPermissions(permissions) || !hasDefinedPermission(Manifest.permission.CAMERA);
}

private void showMediaCaptureOrFilePicker(ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams, boolean isVideo) {
Expand Down Expand Up @@ -523,9 +523,29 @@ private boolean hasPermissions(String[] permissions) {
return true;
}

private void requestPermissions(String[] permissions, int requestCode) {
if (permissions != null) {
ActivityCompat.requestPermissions(this.bridge.getActivity(), permissions, requestCode);
private boolean hasDefinedPermission(String permission) {
boolean hasPermission = false;
String[] requestedPermissions = getManifestPermissions();
if (requestedPermissions != null && requestedPermissions.length > 0) {
List<String> requestedPermissionsList = Arrays.asList(requestedPermissions);
ArrayList<String> requestedPermissionsArrayList = new ArrayList<>(requestedPermissionsList);
if (requestedPermissionsArrayList.contains(permission)) {
hasPermission = true;
}
}
return hasPermission;
}

private String[] getManifestPermissions() {
String[] requestedPermissions = null;
try {
PackageManager pm = bridge.getContext().getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(bridge.getContext().getPackageName(), PackageManager.GET_PERMISSIONS);

if (packageInfo != null) {
requestedPermissions = packageInfo.requestedPermissions;
}
} catch (Exception ex) {}
return requestedPermissions;
}
}

0 comments on commit f502a99

Please sign in to comment.