2016-05-14 12 views
0

Ich versuche eine App zu erstellen, in der ich ein Foto machen und das Miniaturbild anzeigen kann. Ich habe das Tutorial von https://developer.android.com/training/camera/photobasics.html gefolgt, aber ohne Glück.Android kehrt nach der Aufnahme des Fotos nicht zur Aktivität zurück

Das Problem ist, dass meine App nicht zu der Aktivität zurückkehren wird, von der die Kamera gestartet wurde. Stattdessen gibt es meine MainActivity zu und eröffnet die Navigationsleiste ..

Hier ist meine Kamera Aktivität:

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> 

Antwort

0

Versuchen Sie Funktion dispatchTakePictureIntent() wie diese

ändern
private void dispatchTakePictureIntent() { 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); 
} 
+0

noch das gleiche .. – Sytham