I'm trying to create an app where I can take a photo and view the thumbnail.
I've followed the tutorial from https://developer.android.com/training/camera/photobasics.html but with no luck.
The problem is my app won't return to the activity the camera started from. Instead it returns to my MainActivity and opens up the navigation drawer..
Here's my camera activity:
public class CameraTestActivity extends AppCompatActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview_test);
//Haal de toolbar op
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
//zet de toolbar als action bar
setSupportActionBar(toolbar);
//zet de homebutton
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
Button photoButton = (Button) findViewById(R.id.photoButton);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dispatchTakePictureIntent();
}
});
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView bitmap = (ImageView) findViewById(R.id.bitmap);
bitmap.setImageBitmap(imageBitmap);
}
}
}
XML layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ext="http://schemas.android.com/apk/res-auto"
android:id="@+id/testers"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="be.kdg.integratieproject.fragments.FragmentMain">
<TextView
android:id="@+id/feedback_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@color/lightteal"
android:text="Webview"
android:fontFamily="sans-serif-medium"
android:textSize="35sp"
android:paddingTop="19dp"
android:textAlignment="center"
android:height="80dp"
android:textColor="@color/lightgray" />
<include
android:id="@+id/app_bar"
layout="@layout/app_bar_transparant" />
<Button
android:id="@+id/photoButton"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:backgroundTint="@color/darkorange"
android:layout_below="@id/feedback_title"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="foto nemen"
android:textStyle="bold"
android:textColor="@color/white"/>
<ImageView
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_below="@id/photoButton"
android:id="@+id/bitmap"
/>
</RelativeLayout>