Open wahyuafendi opened 1 year ago
this is my source code, its work on android <13 but can't in android 13
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { PERMISSIONS = new String[]{ Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO }; } else { PERMISSIONS = new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA }; }
// Check and request permissions if needed checkAndRequestPermissions();
private void checkAndRequestPermissions() { boolean allPermissionsGranted = true;
// Check if all permissions are granted for (String permission : PERMISSIONS) { int permissionCheck = ContextCompat.checkSelfPermission(this, permission); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { allPermissionsGranted = false; break; } } if (!allPermissionsGranted) { // Request permissions ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_REQUEST_CODE); } else { // All permissions are granted, proceed with your logic (e.g., captureImage()) captureImage(); } } private void captureImage() { Toast.makeText(this, "tuktutkkkk", Toast.LENGTH_SHORT).show(); ImagePicker.Companion.with(PatroliActivity.this) .crop() .cameraOnly() .compress(1024) .crop(3f, 2f) .start(20); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PERMISSION_REQUEST_CODE) { boolean allPermissionsGranted = true; // Check if all requested permissions are granted for (int grantResult : grantResults) { if (grantResult != PackageManager.PERMISSION_GRANTED) { allPermissionsGranted = false; break; } } if (allPermissionsGranted) { // All permissions are granted, proceed with your logic (e.g., captureImage()) captureImage(); } else { // Permissions not granted, handle accordingly (show a message, disable functionality, etc.) // You can show a message or take appropriate action here } } }
I had the same issue and I solved it by upgrading the library version to 2.1
this is my source code, its work on android <13 but can't in android 13
// Check and request permissions if needed checkAndRequestPermissions();
private void checkAndRequestPermissions() { boolean allPermissionsGranted = true;