Andrew King
Andrew King

Reputation: 376

Android ImageView Displays on Emulator but not on Device

I am working in AndroidStudio trying to set an image to display on the screen after it is taken by the camera. This is working flawlessly on the emulator but when I test it on my device (Nexus 5) the image does not show up.

I have tried scaling down my image which didn't work, I also tried using a small image in my drawables folder to make sure it wasn't a file path issue (the drawable image also displayed on the emulator but not on my phone). I also tried converting the bitmap to a drawable and setting it to the background of the imageView which also didn't work. I am not sure what else to try at this point.

EDIT: I should add that if I explicitly add the image in the XML as a background it will show up on my device which makes me think it is my java. On the other hand I can get the image to show up on another activity with this same java code which makes me think it is the layout.

File file = cameraShot;
ImageView leftEye = (ImageView) view.findViewById(R.id.ghostAlign);
if(leftEye != null) {
  Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
  leftEye.setImageBitmap(bmp);
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cameraFrag"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="?selectableItemBackground"
    android:tag="ScopiCamera"
    tools:ignore="UnusedAttribute">


    <FitTextureView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/texture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/ghostAlign"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="false"
        android:alpha="0.5" />
</FrameLayout>

Upvotes: 4

Views: 1193

Answers (2)

Feuby
Feuby

Reputation: 718

I'd suggest you to see if there is no memory problem due to loading your image. See this page from doc in order to reduce memory consumption when loading your image.

I had this problem too, the image was opened on other devices but not on my phone. Maybe by properly loading your bitmap, it will works.

Upvotes: 1

CheChe
CheChe

Reputation: 9

first check

google photo in nexus5 enable status?

if google photo setting's disable

can't file path's use & file open

(check : use file maneger on "file.getAbsolutePath()" )

can't gallery use, naxus's google account disable status

--

second textureView no use'd check

next code possible?

public class MainActivity extends Activity{

static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView leftEye;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    leftEye = (ImageView) findViewById(R.id.ghostAlign);
    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();

        if(leftEye != null) {

            Bitmap imageBitmap = (Bitmap) extras.get("data");
            leftEye.setImageBitmap(imageBitmap);

        }

    }
}

}

if Bitmap on imageview's see. i think, AbsolutePath error

Upvotes: 1

Related Questions