I'm using MediaStore.Images.Media.EXTERNAL_CONTENT_URI with a filter on MediaStore.MediaColumns.DATA and a Cursor to retrieve the images. I need to keep the image path where the images are stored, (which are in sub-folders) because I am using the image path to find the correct images to display them with their parent inventory item. I've tried many different ways with no success except using the MediaStore. This is working. The problem is; the MediaStore.MediaColumn.DATA is deprecated (sigh). So I need to refactor out the deprecated field use.
This is an inventory application where each inventory item has a "Source", "Order Number", "OrderItemNumber" plus other data. I stored the images on the sdCard in a folder I created under "downloads" called "InventoryImages". Under this folder are sub-folders (actual source name), (actual Order Number), (actual Order Item Number). Within the "OrderItemNumber" folder are several images, all for this specific combination.
The Inventory Item data is stored in a sqlite db. ((preloaded)(working on the maintenance pieces)). But I'm really trying to avoid storing the image (blob) in the db. But I am open to any and all suggestions for an alternative. I'd rather not have the images deleted if the application is uninstalled. I currently have 104 inventory items, each with average 4 images.
Again, the included fragment is working, I just need an alternative to the DATA column which the value is the image path.
Fragment:
public class ListViewFragment extends Fragment
implements IAdapterCallback
{
public ArrayList<ImageInfo> getAllMediaStoreImages()
{
ArrayList<ImageInfo> allImages = new ArrayList<>();
String inventoryDirectory;
if(Build.FINGERPRINT.contains("generic"))
inventoryDirectory = "Inventory"; // <-- use this for the emulator
else
inventoryDirectory = "InventoryImages"; // <-- use this for my phone
Uri uri =
MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String selection =
MediaStore.MediaColumns.DATA + " LIKE ? ";
String[] selectionArgs = new String[]{"%" +
inventoryDirectory + "%"};
Cursor cursor =
this.getActivity().getContentResolver().query(uri,
null, selection, selectionArgs, null);
String[] names = cursor.getColumnNames();
try {
if (cursor != null) {
while (cursor.moveToNext())
{
String filePath =
cursor.getString(cursor.getColumnIndex((MediaStore.MediaColumns.*DATA*)));
String fileName =
cursor.getString(cursor.getColumnIndex((MediaStore.MediaColumns.TITLE)));
int inventoryDirectoryLoc =
filePath.indexOf(inventoryDirectory) +
inventoryDirectory.length() + 1;
String matchPath =
filePath.substring(inventoryDirectoryLoc,
filePath.lastIndexOf('/'));
allImages.add(new
ImageInfo(filePath, fileName, matchPath));
}
}
return allImages;
}
catch (Exception x)
{
x.printStackTrace();
return null;
}
finally
{
if(cursor != null)
cursor.close();
}
}