ImageView does not have jpg stored on my phone

advertisements

I'm very much an amateur at this, so I apologize in advance if this has been discussed before and I didn't use the right search terms to find my answer. Any help is greatly appreciated.

I'm trying to do a very basic app with a back button, next button, image file, and caption for each image, with the buttons being used to go from one image/caption pair to the next or back. All images are in the "Pictures" folder in the main directory of the phone, all captions are text strings sequentially numbered.

I got the captions to interact with the buttons right but cannot get the images to work right. I can't even get the first image to show in ImageView, probably either because I'm using the wrong file path or the wrong image commands.

The jpgs are numbered from 0 to 25, simple file names (0.jpg 1.jpg etc.). I made one that worked on an Android 2.3 but can't figure it out for 4.4.4.

I set my initial TextView to show the results of Environment.getExternalStorageDirectory () hoping that this would get my file path right. I've tried with that command and with the text of the returned file path as shown in my // comments in the code. Neither worked unfortunately. The comments are messy because I'm new at this and was just saving possible code options for myself.

I used bitmapDrawable and the /sdcard/ file path in my version that worked on my earlier android. And I've read through about 15-20 of these imageView questions trying different solutions with no luck so far.

I hope this is enough information. If someone can help me out I'd really appreciate it.

public class MainActivity extends ActionBarActivity {
ImageView image;
Button next02, back02;
TextView output01;
int test = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    output01 = (TextView) findViewById(R.id.output);
    next02 = (Button) findViewById(R.id.next);
    next02.setOnClickListener(advance01);
    back02 = (Button) findViewById(R.id.back);
    back02.setOnClickListener(retreat01);
    output01.setText("Test");
    ImageView image01 = (ImageView) findViewById(R.id.picture);

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 3;

    String myJPGPath = Environment.getExternalStorageDirectory() + "/Pictures/00.JPG";
    Bitmap d = BitmapFactory.decodeFile(myJPGPath);
    image01.setImageBitmap(d);
    output01.setText(myJPGPath);

//        String myJpgPath = Environment.getExternalStorageDirectory().toString() + "/0.jpg";
//        String myJpgPath = "/storage/emulated/0/Pictures/0.jpg";
//        File myfile = new File(myJpgPath);
//        output01.setText(myJpgPath);
//        BitmapDrawable d = new BitmapDrawable(getResources(), myJpgPath);
//        image01.setImageDrawable(d);
//        Bitmap d = BitmapFactory.decodeFile(myfile.getAbsolutePath());
//        Bitmap d = BitmapFactory.decodeFile("/storage/emulated/0/0.jpg");
//        image01.setImageBitmap(d);
}
public OnClickListener advance01 = new OnClickListener() {
    public void onClick (View v) {
        test++;
        if (test == 1) {
            output01.setText(text1);

Oops - here's logcat - looks like I have a permissions problem but the picture isn't set to read only. Got a few other problems too - maybe I'll just start this from scratch:

01-03 10:16:55.892  16614-16614/com.test.test I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-03 10:16:55.892  16614-16614/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 11346: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-03 10:16:55.892  16614-16614/com.test.test D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-03 10:16:55.893  16614-16614/com.test.test I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-03 10:16:55.893  16614-16614/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 11352: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-03 10:16:55.893  16614-16614/com.test.test D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-03 10:16:55.894  16614-16614/com.test.test I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-03 10:16:55.894  16614-16614/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 9040: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-03 10:16:55.894  16614-16614/com.test.test D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-03 10:16:55.899  16614-16614/com.test.test I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-03 10:16:55.899  16614-16614/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-03 10:16:55.900  16614-16614/com.test.test D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-03 10:16:55.900  16614-16614/com.test.test I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-03 10:16:55.900  16614-16614/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
01-03 10:16:55.900  16614-16614/com.test.test D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-03 10:16:55.934  16614-16614/com.test.test E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/0.jpg: open failed: EACCES (Permission denied)
01-03 10:16:56.015  16614-16614/com.test.test I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_KK_2.7_RB1.04.04.04.007.066_msm8960_KK_2.7_RB1__release_AU ()
OpenGL ES Shader Compiler Version: 17.01.12.SPL
Build Date: 09/11/14 Thu
Local Branch: mybranch4451390
Remote Branch: quic/kk_2.7_rb1.43
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_KK_2.7_RB1.04.04.04.007.066 + 73685fa + 87c0666 + c4bc670 + 6154422 + 594ea9d +  NOTHING
01-03 10:16:56.062  16614-16614/com.test.test D/OpenGLRenderer﹕ Enabling debug mode 0


Use this code to get the path of your JPG in the Pictures folder:

String myJPGPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath()+"/0.jpg";

Also, with the exception of some SD cards, the Android file system is case sensitive. So "0.JPG" and "0.jpg" are not the same. Make sure you match the filename exactly.