title: camera source code for android eclipse
body: <p>I need some help. the thing is I doing an app on namecard reader and need to use the camera function to take pictures. but how do I make my app able to view the mutiple pic that I have save without having to exit the app and go to the gallery? below is the camera source code that I use.. thank</p>
  
  <p>`</p>
  
  <p>CameraMainActivity.Java</p>
  
  <pre><code>private static final int REQUEST_CODE = 1;
  private static final int CAMERA_PIC_REQUEST = 1337;
  private Bitmap bitmap;
  private ImageView imageView;
  private Button save, capture;
  
  /** Called when the activity is first created. */
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_camera_main);
      imageView = (ImageView) findViewById(R.id.result);
      save = (Button) findViewById(R.id.save);
      save.setOnClickListener(this);
      capture = (Button) findViewById(R.id.capture);
      capture.setOnClickListener(this);
  }
  
  public void captureImage() {
      // Capture image from camera
  
          Intent intent = new Intent(
                  android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  
          startActivityForResult(intent, CAMERA_PIC_REQUEST);
  
  }
  
  public void pickImage() {
      // To pick a image from file system
      Intent intent = new Intent();
      intent.setType("image/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      startActivityForResult(intent, REQUEST_CODE);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == Activity.RESULT_OK) {
          if (requestCode == REQUEST_CODE) {
              try {
                  // We need to recycle unused bitmaps
                  if (bitmap != null) {
                      bitmap.recycle();
                  }
                  InputStream stream = getContentResolver().openInputStream(
                          data.getData());
                  bitmap = BitmapFactory.decodeStream(stream);
                  stream.close();
                  imageView.setImageBitmap(bitmap);
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } else if (requestCode == CAMERA_PIC_REQUEST) {
  
                  if (bitmap != null) {
                      bitmap.recycle();
                  }
                  bitmap = (Bitmap) data.getExtras().get("data");
                  if (data.getExtras().get("data") == null)
                  Toast.makeText(getApplicationContext(),
                          "No image returned", Toast.LENGTH_LONG).show();
                  else
                  imageView.setImageBitmap(bitmap);
  
  
  
          }
      }
      super.onActivityResult(requestCode, resultCode, data);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.activity_camera_main, menu);
      return true;
  }
  
  @Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
      if (v == save) {
          BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
          Bitmap bitmap = drawable.getBitmap();
          File sdCardDirectory = Environment.getExternalStorageDirectory();
          File image = new File(sdCardDirectory, "test.png");
          boolean success = false;
  
          // Encode the file as a PNG image.
          FileOutputStream outStream;
          try {
  
              outStream = new FileOutputStream(image);
              bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
              /* 100 to keep full quality of the image */
  
              outStream.flush();
              outStream.close();
              success = true;
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (success) {
              Toast.makeText(getApplicationContext(),
                      "Image saved with success", Toast.LENGTH_LONG).show();
          } else {
              Toast.makeText(getApplicationContext(),
                      "Error during image saving", Toast.LENGTH_LONG).show();
          }
      } else if (v == capture) {
          captureImage();
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i'm using a button to launch the camera</p>
  
  <p>main.xml</p>
  
  <pre><code>    &lt;Button
          android:id="@+id/takeviewpic"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Take/View Pic" /&gt;
  </code></pre>
  
  <p>Android Manifest</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  &lt;uses-permission android:name="android.permission.CALL_PHONE"/&gt;
  &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-feature
      android:name="android.hardware.camera"
      android:required="false" /&gt;
  &lt;uses-feature
      android:name="android.hardware.camera.front"
      android:required="false" /&gt;
  &lt;uses-feature
      android:name="android.hardware.camera.autofocus"
      android:required="false" /&gt;
  &lt;uses-feature
      android:name="android.hardware.camera.flash"
      android:required="false" /&gt;
  &lt;uses-feature android:name="android.hardware.screen.landscape" /&gt;
  &lt;uses-feature
      android:name="android.hardware.wifi"
      android:required="false" /&gt;
  &lt;uses-feature
      android:name="android.hardware.touchscreen"
      android:required="false" /&gt;
  
  &lt;uses-sdk android:minSdkVersion="10" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;uses-library android:name="com.google.android.maps" /&gt;
      &lt;activity
          android:name="sp.com.Splash"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".Main"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="main" /&gt;
  
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=".NameCardList" &gt;
      &lt;/activity&gt;
      &lt;activity android:name=".DetailForm" &gt;
      &lt;/activity&gt;
      &lt;activity android:name=".EditPreferences" &gt;
      &lt;/activity&gt;
      &lt;activity android:name=".NameCardMap" &gt;
      &lt;/activity&gt;
      &lt;activity android:name=".SmsReceiver" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".CameraMainActivity"
          android:label="@string/app_name" 
          android:clearTaskOnLaunch="true"
          android:configChanges="orientation|keyboardHidden"
          android:stateNotNeeded="true"
      /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>`</p>