Capturing image from gallery & camera in android
Take a look at LinderdaumEngineActivity.java
from my project Linderdaum Engine:
Capture image from camera:
public void CapturePhoto( String FileName )
{
try
{
File f = new File(FileName);
if ( f.exists() && f.canWrite() ) f.delete();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(f));
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_CALLBACK);
}
catch ( ActivityNotFoundException e )
{
Log.e( TAG, "No camera: " + e );
}
catch ( Exception e )
{
Log.e( TAG, "Cannot make photo: " + e );
}
}
Open image from gallery:
public static void OpenImage()
{
try
{
Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
intent.setType( "image/*" );
startActivityForResult( intent, SELECT_PICTURE_CALLBACK );
}
catch ( ActivityNotFoundException e )
{
Log.e( TAG, "No gallery: " + e );
}
}
Also, do not forget to add permissions to your manifest:
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA" android:required="false"/>
Please check your AndroidManifest, make sure you have all the right permissions.