【发布时间】:2020-01-01 02:59:38
【问题描述】:
我已经尝试过所有其他帖子的答案,它们似乎都返回 0.0 作为我图像的文件大小,这不可能是真的。我认为文件路径是导致它返回不正确文件大小的原因。这是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
imageUri = data.getData();
textViewImageAttachmentStatus.setText("File has been attached");
textViewImageAttachmentStatus.setTextColor(Color.parseColor("#008577"));
Picasso.get().load(imageUri).into(imageViewPreviewImage);
String imagePath = imageUri.getPath();
File imageFile = new File(imagePath);
long imageSize = imageFile.length() / 1024;
System.out.println(imageSize);
}
}
【问题讨论】:
-
你能登录 imageUri.getPath() 吗?
-
给你朋友 - “I/System.out: /document/image:89506”
-
hmm 你可以尝试使用光标检索文件吗? ,我会分享
-
这能回答你的问题吗? Get the size of an Android file resource?
-
@SanjayBhalani 在该问题的已接受答案中,作者提到了 R.raw.nameOfFile。如果没有,我会为“nameOfFile”传递什么?
标签: android