package com.commonsware.android.camcon;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import java.io.File;

public class CameraContentDemoActivity extends Activity {
  private static final int CONTENT_REQUEST=1337;
  private File output=null;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File dir=
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

    output=new File(dir, "CameraContentDemo.jpeg");
    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));

    startActivityForResult(i, CONTENT_REQUEST);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode,
                                  Intent data) {
    if (requestCode == CONTENT_REQUEST) {
      if (resultCode == RESULT_OK) {
        Intent i=new Intent(Intent.ACTION_VIEW);
        
        i.setDataAndType(Uri.fromFile(output), "image/jpeg");
        startActivity(i);
        finish();
      }
    }
  }
}
@@ -1,8 +1,674 @@
+/***%0A Copyright (c) 2008-2016 CommonsWare, LLC%0A Licensed under the Apache License, Version 2.0 (the %22License%22); you may not%0A use this file except in compliance with the License. You may obtain a copy%0A of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required%0A by applicable law or agreed to in writing, software distributed under the%0A License is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS%0A OF ANY KIND, either express or implied. See the License for the specific%0A language governing permissions and limitations under the License.%0A%0A From _The Busy Coder's Guide to Android Development_%0A https://commonsware.com/Android%0A */%0A%0A
 package 
@@ -957,16 +957,180 @@
 ivity %7B%0A
+  private static final String EXTRA_FILENAME=%0A    %22com.commonsware.android.camcon.EXTRA_FILENAME%22;%0A  private static final String FILENAME=%22CameraContentDemo.jpeg%22;%0A
   privat
@@ -1362,16 +1362,55 @@
 PTURE);%0A
+%0A    if (savedInstanceState==null) %7B%0A  
     File
@@ -1507,165 +1507,492 @@
     
-output=new File(dir, %22CameraContentDemo.jpeg%22);%0A    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));%0A%0A    startActivityForResult(i, CONTENT_REQUEST
+  dir.mkdirs();%0A      output=new File(dir, FILENAME);%0A    %7D%0A    else %7B%0A      output=(File)savedInstanceState.getSerializable(EXTRA_FILENAME);%0A    %7D%0A%0A    if (output.exists()) %7B%0A      output.delete();%0A    %7D%0A%0A    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));%0A%0A    startActivityForResult(i, CONTENT_REQUEST);%0A  %7D%0A%0A  @Override%0A  protected void onSaveInstanceState(Bundle outState) %7B%0A    super.onSaveInstanceState(outState);%0A%0A    outState.putSerializable(EXTRA_FILENAME, output
 );%0A 

handle config changes/process termination