Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Taking a Photo Using an Intent

DeVontae Moore
DeVontae Moore
2,182 Points

Why isn't my code launching my camera application?

public class BibleVersesActivity extends AppCompatActivity {

public static final String TAG = BibleVersesActivity.class.getSimpleName();

public static final int REQUEST_TAKE_PHOTO = 0;
public static final int REQUEST_TAKE_VIDEO = 1;
public static final int REQUEST_PICK_PHOTO = 2;
public static final int REQUEST_PICK_VIDEO = 3;

public static final int MEDIA_TYPE_IMAGE = 4;
public static final int MEDIA_TYPE_VIDEO = 5;





@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bible_verses);
    ButterKnife.bind(this);



    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {

    }
    else if (resultCode != RESULT_CANCELED) {
        Toast.makeText(this, "Sorry, there was an error!", Toast.LENGTH_LONG).show();
    }
}

@OnClick(R.id.imageButton2)
void takePhoto() {
    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(takePhotoIntent, REQUEST_TAKE_PHOTO);
}

}

1 Answer

Add in build.gradle (app)

dependencies { implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' }