someguysomewhere
Lurker
First off, I just started experimenting with writing Android apps for about the last week, so I'm still very much a noob at this.
The problem I'm having is I've written a camera type app that takes an image, using the Android devices built in camera, then sends a display of the image back to the app. It worked fine until I wanted to save the image automatically to the devices camera roll after taking the image. I put in this code and now it wont display the image back into the app like before:
Here is the whole MainActivity.java file:
Does it have to do with EXTRA_OUTPUT returning a null value?
The problem I'm having is I've written a camera type app that takes an image, using the Android devices built in camera, then sends a display of the image back to the app. It worked fine until I wanted to save the image automatically to the devices camera roll after taking the image. I put in this code and now it wont display the image back into the app like before:
Code:
File file = new File(Environment.getExternalStorageDirectory(), CurrentDateAndTime + ".jpg");
Uri photoPath = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath);
Code:
package com.example.camera;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
Button btnTackPic;
ImageView ivThumbnailPhoto;
Bitmap bitMap;
static int TAKE_PICTURE = 1;
String CurrentDateAndTime= getCurrentDateAndTime();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTackPic = (Button) findViewById(R.id.btnTakePic);
ivThumbnailPhoto = (ImageView) findViewById(R.id.ivThumbnailPhoto);
btnTackPic.setOnClickListener(this);
}
private String getCurrentDateAndTime()
{
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String formattedDate = df.format(c.getTime());
return formattedDate;
}
@Override
public void onClick(View view)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), CurrentDateAndTime + ".jpg");
Uri photoPath = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == TAKE_PICTURE && resultCode== RESULT_OK && intent != null)
{
Bundle extras = intent.getExtras();
bitMap = (Bitmap) extras.get("data");
ivThumbnailPhoto.setImageBitmap(bitMap);
}
}
}