2016-11-01 41 views
1

enter image description here获取图像的文件路径INTERNAL存储

我的智能手机是LG G2。正如您在图片中看到的,LG G2使用INTERNAL STORAGE拍摄图像。好。但是这个图像的路径是什么?

File fileToUpload = new File(getFilesDir().getAbsolutePath() + "20160525_200312.jpg"); 

我试过这个,但它给出了这个错误。

E/Parcel:读取这里不支持的NULL字符串。

+0

“当你在图片中看到,LG G2采用了图像的内部存储” - LG自曝*用户名*为“内部存储”的卷。从Android SDK的角度来看,这就是[外部存储](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html)。用户无法访问Android SDK引用的[内部存储](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html)。 – CommonsWare

+0

那么如何在图片中获取图片文件呢? –

+0

根据upvoted的答案,使用'Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)'。 – CommonsWare

回答

1

尝试

Environment.DIRECTORY_DCIM; 

或者

Environment.getExternalStoragePublicDirectory(
      Environment.DIRECTORY_DCIM).getAbsolutePath(); 

像:

String baseDir = Environment.getExternalStoragePublicDirectory(
       Environment.DIRECTORY_DCIM).getAbsolutePath(); 
String fileName = "20160525_200312.jpg"; 

File fileToUpload = new File(baseDir + File.separator + fileName); 
+0

那又如何?我是文件的新手。何处添加此代码我无法理解。 –

+0

File fileToUpload = new File(Environment.DIRECTORY_DCIM).getAbsolutePath()+“20160525_200312.jpg”); 是否这样? –

+0

您的问题已解决? –