- Forum posts: 2
Oct 29, 2015, 3:26:15 PM via Website
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?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.