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

Request camera permission for Android 6.0 #84

Open
askarsyzdykov opened this issue Nov 8, 2015 · 1 comment
Open

Request camera permission for Android 6.0 #84

askarsyzdykov opened this issue Nov 8, 2015 · 1 comment

Comments

@askarsyzdykov
Copy link

No description provided.

@jpavlo
Copy link

jpavlo commented Feb 10, 2016

        if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
            getImages();
        }else{
            if(shouldShowRequestPermissionRationale(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)){
                Toast.makeText(this, "External Storage Required to Save Photos", Toast.LENGTH_SHORT).show();
            }
            requestPermissions(new String[] {android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA},
                    REQUEST_EXTERNAL_STORAGE_RESULT);
        }




@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if(requestCode == REQUEST_EXTERNAL_STORAGE_RESULT){
        if(grantResults[0] == PackageManager.PERMISSION_GRANTED){
            getImages();
        } else{
            Toast.makeText(ViewOneGalleryActivity.this, "External Write Permissions have not been granted, cannot save images",
                    Toast.LENGTH_SHORT).show();
        }
    } else{
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}




private void getImages() {
    Intent intent = new Intent(this, ImagePickerActivity.class);

    Config config = new Config.Builder()
            .setTabBackgroundColor(R.color.white)    // set tab background color. Default white.
            .setTabSelectionIndicatorColor(R.color.blue)
            .setCameraButtonColor(R.color.green)
            .setSelectionLimit(50)    // set photo selection limit. Default unlimited selection.
            .build();
    ImagePickerActivity.setConfig(config);
    startActivityForResult(intent, 200);
}

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