I have been struggling with this problem for a few days now and cannot seem to get past it. Basically I have an activity that has 3 image views with a button that starts the camera intent
The problem is that while I am developing and running through the debugger, everything works perfectly but not when I run the app alone (no debugger, just on the phone) after accepting the picture preview it just shows a black screen and does nothing after that.
All that is needed is for the picture to display in the image views and save to the gallery, it does all of this while in debug mode but not when I need to run the app independently.
I am completely at a loss with this problem - please can someone / anyone assist me.
I think this may be an async issue but I am very new to android and dont know how to implement this, in my head and through the tutorials I have read / watched - this should be an easy process, however I cannot seem to get it to work
Here is my code on the layout for the activity:
="1.0"="utf-8"
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PhotoActivity">
<ImageView
android:id="@+id/imgPhoto1"
android:layout_width="236dp"
android:layout_height="136dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/dds_logo" />
<ImageView
android:id="@+id/imgPhoto2"
android:layout_width="236dp"
android:layout_height="136dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imgPhoto1"
app:srcCompat="@drawable/dds_logo" />
<ImageView
android:id="@+id/imgPhoto3"
android:layout_width="236dp"
android:layout_height="136dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imgPhoto2"
app:srcCompat="@drawable/dds_logo" />
<Button
android:id="@+id/btnTakePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="52dp"
android:text="Take Photo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imgPhoto3"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
Here is the code for the onClick event:
public void onClick(View v) {
try {
if (v.getId() == R.id.btnTakePhoto) {
captureImage();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
Here is the call to the intent:
private void captureImage() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, CAPTURE_IMAGE_REQUEST);
}
Here is the onActivtyResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try{
if (!Debug.isDebuggerConnected()){
Debug.waitForDebugger();
Log.d("debug", "started");
}
if(numPhotos < 2) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
String savedImageURL = MediaStore.Images.Media.insertImage(
getContentResolver(),
imageBitmap,
"Serial",
"Refresh Verification photo"
);
switch (numPhotos) {
case 0:
imgPhoto1.setImageBitmap(imageBitmap);
break;
case 1:
imgPhoto2.setImageBitmap(imageBitmap);
break;
case 2:
imgPhoto3.setImageBitmap(imageBitmap);
break;
}
numPhotos++;
}
else
{
numPhotos = 0;
Toast.makeText(PhotoActivity.this, "Max # of ohotos reached", Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MenuActivity.class);
startActivity(i);
finish();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
What I have tried:
I have tried only saving the image and not displaying it in the imageview but still no luck. It still only works when connected to the IDE in debug mode and not when deployed to the device.