Camera With Intent : Camera « Hardware « Android






Camera With Intent

   
package app.test;

import java.io.File;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.View;

public class Test extends Activity {
  Uri myPicture = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    public void captureImage(View view){
      ContentValues values = new ContentValues();
        values.put(Media.TITLE, "My demo image");
        values.put(Media.DESCRIPTION, "Image Captured by Camera via an Intent");
        myPicture = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        i.putExtra(MediaStore.EXTRA_OUTPUT, myPicture);
        startActivityForResult(i, 0);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==0 && resultCode==Activity.RESULT_OK)
        {
             Intent inn = new Intent(Intent.ACTION_VIEW);
             inn.setData(myPicture);
             startActivity(inn);
        }
    }
}

   
    
    
  








Related examples in the same category

1.Camera preview
2.Camera Intent
3.Media Store Camera Intent
4.Using Timer to control Camera
5.Camera orientation
6.Camera Preview and Camera.getNumberOfCameras()
7.Take a snapshot
8.Take and preview Photo
9.A grid that displays a set of framed photos.