Imageview not showing image on a specific tablet

  • Replies:3
Federico
  • Forum posts: 2

Oct 29, 2015, 3:26:15 PM via Website

Hey guys!

I'm stuck in the following problem and I don't know what to do:

Main Activity:

package com.example.rwallpapers;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {
ImageView mImageView;
String path1 = "/mnt/internal_sd/Pictures/RP/1.png"; 
String path2 = "/mnt/internal_sd/Pictures/RP/2.png";
String path3 = "/mnt/internal_sd/Pictures/RP/3.png";
String path4 = "/mnt/internal_sd/Pictures/RP/4.png";
String path5 = "/mnt/internal_sd/Pictures/RP/5.png";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
    public void launchImageView(View v) {
        switch (v.getId()) {
            case R.id.imageButton1:
                Intent i = new Intent(this, ImageViewActivity.class);
                i = new Intent(this, ImageViewActivity.class);
                //i.setData(Uri.parse(path1));
                i.setData(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Pictures/RP/1.png"));
                startActivity(i);
            break;
            case R.id.imageButton2:
                i = new Intent(this, ImageViewActivity.class);
                //i.setData(Uri.parse(path2));
                i.setData(Uri.parse(Environment.getExternalStorageDirectory()+"/Pictures/RP/2.png"));
                startActivity(i);
                break;
            case R.id.imageButton3:
                i = new Intent(this, ImageViewActivity.class);
                i.setData(Uri.parse(path3));
                //i.setData(Uri.parse(Environment.getExternalStorageDirectory()+"/Pictures/RP/3.png"));

                startActivity(i);
                break;
            case R.id.imageButton4:
                i = new Intent(this, ImageViewActivity.class);
                i.setData(Uri.parse(path4));
                //i.setData(Uri.parse(Environment.getExternalStorageDirectory()+"/Pictures/RP/4.png"));
                startActivity(i);
                break;
            case R.id.imageButton5:
                i = new Intent(this, ImageViewActivity.class);
                i.setData(Uri.parse(path5));
                //i.setData(Uri.parse(Environment.getExternalStorageDirectory()+"/Pictures/RP/5.png"));
                startActivity(i);
                break;

        }
    }
}

ImageViewActivity:

package com.example.rwallpapers;

import android.os.Bundle;
import android.widget.ImageView;

public class ImageViewActivity extends MainActivity {
    ImageView im;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imageview);

    im = (ImageView) findViewById(R.id.image_content);

    im.setImageURI(getIntent().getData());

    //Toast.makeText(getApplicationContext(),"hello", Toast.LENGTH_LONG).show();        
}
}

In the manifest I wrote the permission:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

I tested this on my phone and on a tablet and it works perfectly. Using this:

i.setData(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Pictures/RP/1.png"));

Or this:

i.setData(Uri.parse(Environment.getExternalStorageDirectory()+"/Pictures/RP/2.png"));

Or even the hardcoded path.

But on the tablet that we are releasing it does not show the image on the imageview.

This path is the one that appears if I see the properties of the file on a file explorer:

"/mnt/internal_sd/Pictures/RP/1.png"

Even if I hardcoded it, it doesn't work.

And this is what the file explorer says at the top:

NAND FLASH/Pictures/RP

The tablet is running Android 5.1.1.

What am I missing?

Reply
Ashish Tripathi
  • Forum posts: 211

Oct 30, 2015, 6:18:24 AM via Website

put this code in try catch. i suppose there is some exception is coming. Just try this and share the results.

runonuithread(new Runnable)
{
public void run()
{
try{
im.setImageURI(getIntent().getData());
}
catch(Exception ex){
ex.prinstacktrace()
}
}

Reply
Federico
  • Forum posts: 2

Oct 30, 2015, 9:13:13 PM via Website

I change the permission from READ_EXTERNAL_STORAGE to WRITE_EXTERNAL_STORAGE and now it works flawlessly. Do you know why?

Reply
Shirley
  • Forum posts: 17

Dec 30, 2015, 2:11:04 PM via Website

I prefer using Leomaster Privacy Guard to lock my apps. They just released version 3.0 with many new features.
You should give that a try! :)

Reply