Camera-intent to android marshmallow

For this tutorial we describe how to upgrade the camera-intent to android marshmallow. Which will adding runtime permissions for writing to external storage.

The security permissions in android marshmallow have gone through significant changes where the user now grants permissions while using the application instead of the old way which was to accept a list  of permissions prior to installing the application.

The new permission model does require more work and thought from the developer in how to present  the required permissions to the user but does provide the user more choice with what data and personal information they want to share with the application.

The camera intent application requires two permissions to function, the write access to external storage and the access to an external camera application.

Because the application will be requesting access to the android camera application via an android intent no runtime permissions will be required for the camera, just write access to external storage.

This tutorial will describe the steps required to provide the write access to external storage runtime permission.

Get Code

The code is now on github you can get it from here Tag camera-intent-marshmallow

or else run this command

git clone –branch camera-intent-marshmallow

Code Samples

Change SDK version & add appcompat v7 library support


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.mobapptuts.cameraintent"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ""

Add runtime permissions for write external storage

Add request code

private static final int REQUEST_EXTERNAL_STORAGE_RESULT = 1;

Create method for calling camera app via intent

private void callCameraApp() {
    Intent callCameraApplicationIntent = new Intent();

    File photoFile = null;
    try {
        photoFile = createImageFile();

    } catch (IOException e) {
    callCameraApplicationIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));

    startActivityForResult(callCameraApplicationIntent, ACTIVITY_START_CAMERA_APP);


Implement the runtime permission request

public void takePhoto(View view) {
       if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
           if (ContextCompat.checkSelfPermission(this,
                   Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
           } else {
               if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                           "External storage permission required to save images",
               requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
       } else {

Setup the callback for the result of the permission request

   public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
       if(requestCode == REQUEST_EXTERNAL_STORAGE_RESULT) {
           if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
           } else {
                       "External write permission has not been granted, cannot saved images",
       } else {
           super.onRequestPermissionsResult(requestCode, permissions, grantResults);

How to revoke the android marshmallow runtime permissions

The command to revoke the android marshmallow runtime permissions is in this format

adb shell pm revoke com.mobapptuts.cameraintnet android.permission.WRITE_EXTERNAL_STORAGE
About The Author

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>