我正在尝试扫描所有可用图像的内部存储空间,但得到0结果,其中,我在扫描之前存储了一个图像,该图像是“wallpaper.jpg”。
提前感谢您的帮助。
boolean fileFlag= fileExistance("/wallpaper.jpg");
System.out.println(fileFlag); // this returns "true"
initMediaContentLevels(TAG, Images.Media.INTERNAL_CONTENT_URI, CoreConstants.DATATYPE_PHOTO, listener);
protected void initMediaContentLevels(final String tag, final Uri mediaUri, final int dataType, final DataManagerListener listener) {
LOG.i(TAG, "initMediaContentLevels("+tag+","+mediaUri+","+dataType+") mClassItemsTotal="+mClassItemsTotal);
//TODO if the data card is not mounted or missing then this returns 0 .. should test that sd card is available when app starts
String[] projection = {MediaStore.MediaColumns.DATA};
Cursor mediaExtCur = sContext.getContentResolver().query(
mediaUri,
projection,
null,
null,
null);
LOG.d(TAG, "initMediaContentLevels("+tag+","+mediaUri+","+dataType+") mediaExtCur="+mediaExtCur);
if (mediaExtCur!=null) {
int numItems = mediaExtCur.getCount(); //allows for chaining of class for one upload group (row of UI)
LOG.d(TAG, "initMediaContentLevels("+tag+") numItems="+numItems);
try {
if (numItems > 0) {
while (mediaExtCur.moveToNext()) {
String filepath = getString(mediaExtCur, MediaColumns.DATA);
File f = new File(filepath);
if (!f.exists() || !f.canRead()) {
LOG.e(TAG, "initMediaContentLevels("+tag+") file "+f.getAbsolutePath()+" "+(f.exists()?"is not readable":"does not exist"));
continue;
}
long fileSize = f.length();
if (exceedsFileSizeLimit(fileSize)) {
LOG.e(TAG, "initMediaContentLevels("+tag+") file is too large to announce "+filepath+": "+fileSize);
//files larger than the max are not counted
continue;
}
mBytesTotal += fileSize; //db sizes are unreliable
mClassItemsTotal++;
}
LOG.d(TAG, "initMediaContentLevels("+tag+") mBytesTotal="+mBytesTotal+", mClassItemsTotal="+mClassItemsTotal);
}
}
catch (Exception e) {
LOG.e(TAG,"problem getting media count "+e.toString());
}
finally {
if (!mediaExtCur.isClosed()) {
mediaExtCur.close();
}
}
}
LOG.d(TAG, "initMediaContentLevels("+tag+") listener="+listener);
listener.initialiseClassCount(dataType, mClassItemsTotal, mBytesTotal);
LOG.d(TAG, "initMediaContentLevels("+tag+") done");
}