写真を撮り、データと画像をSDカードに保存して、画像データを読み取って出力できるアクティビティを作成しようとしています。しかし、showPhoto() メソッドで「Constructor File(Uri) is undefined.」というエラーが発生します。誰か助けてくれませんか??
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager.OnActivityResultListener;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class CallCamera extends Activity {
private static final String TAG = "CallCamera";
private static final int CAPTURE_IMAGE_ACTIVITY_REQ = 0;
Uri fileUri = null;
ImageView photoImage = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_camera);
photoImage=(ImageView) findViewById(R.id.photo_image);
Button callCameraButton = (Button)findViewById(R.id.button_callcamera);
callCameraButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Intent i= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = getOutputPhotoFile();
fileUri=Uri.fromFile(getOutputPhotoFile());
i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQ); //returns photo file to activity when camera is done
}
//store photo taken on SD card
private File getOutputPhotoFile() {
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),getPackageName());
if (!directory.exists()){
if(!directory.mkdirs()){
Log.e(TAG,"Failed to create storage directory.");
return null;
}
}
//set photo name with standard time linked and store on sdCard in standard picture directory
String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss",Locale.ENGLISH).format(new Date());
return new File(directory.getPath() + File.separator + "IMG_"+timeStamp+".jpg");
}
protected void onActivityResult (int requestCode, int resultCode, Intent data){
if (requestCode==CAPTURE_IMAGE_ACTIVITY_REQ){
if(resultCode==RESULT_OK){
Uri photoUri = null;
if (data==null){
//confirming image save
Toast.makeText(CallCamera.this, "Image saved successfully", Toast.LENGTH_LONG).show();
photoUri=fileUri;
} else {
photoUri = data.getData();
Toast.makeText(CallCamera.this, "imaged saved successfully in: " + data.getData(), Toast.LENGTH_LONG).show();
}
photoUri = data.getData();
showPhoto(photoUri);
} else if (resultCode==RESULT_CANCELED) {
Toast.makeText( CallCamera.this,"Cancelled", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(CallCamera.this, "Callout for image capture failed!", Toast.LENGTH_LONG).show();
}
}
}
});
}
protected void showPhoto(Uri photoUri) {
File imageFile = new File(photoUri);
if (imageFile.exists()){
Drawable oldDrawable = photoImage.getDrawable();if(oldDrawable !=null) { ((BitmapDrawable)oldDrawable).getBitmap().recycle();
}
}
if (imageFile.exists()){
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
BitmapDrawable drawable = new BitmapDrawable(this.getResources(),bitmap);
photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);;
photoImage.setImageDrawable(drawable);
}
}