我onActivityResult从mediastore图像选择返回,我可以使用以下内容获取图像的URI:
Uri selectedImage = data.getData();
Run Code Online (Sandbox Code Playgroud)
将其转换为字符串可以得到:
content://media/external/images/media/47
Run Code Online (Sandbox Code Playgroud)
或者路径给出:
/external/images/media/47
Run Code Online (Sandbox Code Playgroud)
但是我似乎无法找到将其转换为绝对路径的方法,因为我想将图像加载到位图而不必将其复制到某处.我知道这可以使用URI和内容解析器完成,但这似乎在重新启动手机时中断,我想MediaStore在重新启动之间不会保持其编号相同.
我想在已存储的SD卡中显示ImageView中的Bitmap图像.运行后我的应用程序崩溃并导致OutOfMemoryError错误:
(java.lang.OutOfMemoryError:无法分配带有2097152个空闲字节的23970828字节分配和2MB直到OOM)
我不知道或为什么它的内存不足.我认为我的图像尺寸非常大,所以我试图改变它.
Iterator<String> it = imageArray.iterator();
while (it.hasNext()) {
Object element = it.next();
String objElement = element.toString();
Log.e("objElement ", " = " + objElement);
final ImageView imageView = new ImageView (getContext());
final ProgressBar pBar = new ProgressBar(getContext(), null,
android.R.attr.progressBarStyleSmall);
imageView.setTag(it);
pBar.setTag(it);
imageView.setImageResource(R.drawable.img_placeholder);
pBar.setVisibility(View.VISIBLE);
if (objElement.endsWith(mp3_Pattern)) {
Log.e("Mp3 ", " ends with ");
pBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.audio_control);
}
if (objElement.endsWith(png_Pattern)) {
Bitmap bitmap = BitmapFactory.decodeFile(objElement);
int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
int x = (bitmap.getWidth() - size) …Run Code Online (Sandbox Code Playgroud) 然后在API级别为23的真实设备上调试它:
问题是当我尝试通过Android OS自己的类进行调试时,我得到'源代码与字节码不匹配'.为什么会这样?应用程序运行的测试设备是API级别23,正在调试的源文件也是级别23.

我真的很困惑.任何人都可以解释为什么我看到这个消息以及我如何解决它?
java android android-debug android-studio android-6.0.1-marshmallow
我有一个非常奇怪的问题。我正在从图库中挑选一张图片,该代码在诺基亚 6、一加 X 等所有设备上都可以正常工作。当涉及到小米设备时,该图片没有设置好ImageView。
谁能帮我解决这个问题?我必须选择多个图像。
从图库中选择图像的代码
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
Run Code Online (Sandbox Code Playgroud)