Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help me, liblary cant work on android 13 #330

Open
wahyuafendi opened this issue Sep 4, 2023 · 1 comment
Open

Help me, liblary cant work on android 13 #330

wahyuafendi opened this issue Sep 4, 2023 · 1 comment

Comments

@wahyuafendi
Copy link

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
        }
    }
}
@redha96
Copy link

redha96 commented Feb 14, 2024

I had the same issue and I solved it by upgrading the library version to 2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants