I have a View with a button and an imageview. There I want to take a large size photo with the android camera and set it in the imageview. With the following Code I get no Image in the imageview. What is wrong in my code?Please help.Thank you for help
package de.camera.test;
...
public class CameratestActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
public File mTemp;
public ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button cameraButton = (Button) findViewById(R.id.button);
image = (ImageView) findViewById(R.id.imageview);
cameraButton.setOnClickListener(this);
}
public void onClick(View v) {
Intent camera = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
mTemp = File.createTempFile("myCameraShot", null);
camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
Uri.fromFile(mTemp));
startActivityForResult(camera, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null)
return;
Bitmap b;
try {
b = Media.getBitmap(getContentResolver(), Uri.fromFile(mTemp));
image.setImageBitmap(b);
Drawable d = image.getDrawable();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>