Tuesday, February 18, 2014

How to get a picture android SD card specified folder Uri uri problem


posts by wangkai88 on 2012-06-29 15:07:35 Edit
String a = "file :/ /" + Environment.getExternalStorageDirectory () getPath () + "/ dcim / Camera /";.
/ / File baseFile = new File (a + "/ dcim/Camera/15.jpg");

/ / Uri uri = Uri.fromFile (baseFile);
/ / Uri uri = Uri.parse (a);
/ / Read the SD card all the pictures
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String [] projection = {MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE};
"? =" String selection = MediaStore.Images.Media.MIME_TYPE +;
String [] selectionArg = {"image / jpeg"};
Cursor mCursor = this.managedQuery (uri, projection, selection,
selectionArg, MediaStore.Images.Media.DATE_MODIFIED + "desc");
imageList.clear ();
if (mCursor! = null) {
mCursor.moveToFirst ();
while (mCursor.getPosition ()! = mCursor.getCount ()) {
imageMap = new HashMap ();
imageMap.put (imageID, mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media._ID)));
imageMap.put (imageName, mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media.DISPLAY_NAME)));
imageMap.put (
imageInfo,
""
+ (MCursor.getLong (mCursor
. GetColumnIndex (MediaStore.Images.Media.SIZE)) / 1024)
+ "KB");
imageList.add (imageMap);
fileNames.add (mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media.DATA)));
mCursor.moveToNext ();
}
mCursor.close ();
}


/ / Read the SD card all the pictures
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

The way to get all the pictures no problem, but I changed to the specified folder path SD card but not

String a = "file :/ /" + Environment.getExternalStorageDirectory () getPath () + "/ dcim / Camera /";.
/ / File baseFile = new File (a + "/ dcim/Camera/15.jpg");

/ / Uri uri = Uri.fromFile (baseFile);
Uri uri = Uri.parse (a);
Have tried not work, I do not know of Caesar, please take prompt large<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
In front of a need to add "file :/ /" it?
Reply:
String a = "file :/ /" + Environment.getExternalStorageDirectory () getPath () + "/ DCIM / Camera /";. Attention to the case ~ ~ ~
Reply:
This is the capital DCIM it? ? I use eclipse resource manager looked under the folder is lowercase,
String a = "file :/ /"
+ Environment.getExternalStorageDirectory (). GetPath ()
+ "/ DCIM / Camera /";
Uri uri = Uri.parse (a);
Debugging write reproduce the same image
Reply:

File file = new File ("/ mnt/sdcard/CameraTest/1024_768.jpg");
/ / If (file.exists ()) {
if (file.delete ()) {
Log.e ("del", "delete the file successfully");
loadImageList ();
} Else {
System.out.println ("File not found what you want, oh");
}


/ /} Else {
/ / System.out.println ("File not found what you want, oh");
/ /}


Will android delete () Why Can not delete file file.exists () also returns did not find the file I am looking at the inside just delete this file SD
Reply:
If a folder file.delete () deletes all the files in its directory folder still exists - but if it is not directly delete the folder!
Reply:
Upstairs is very clear, learning
Reply:
Additional information: also need to consider deleting the file permissions problem!
Reply:
File file = new File ("/ mnt/sdcard/CameraTest/1024_768.jpg");
To File file = new File ("/ sdcard/CameraTest/1024_768.jpg"); This trip does not need / mnt
Reply:
I want it to find out how to get the images only from a specific folder, not all of the images. Here is the code I use
/ / Get the image list
private ArrayList > GetImageList () {

ArrayList > imageList = new ArrayList > ();
HashMap imageMap;
/ / String a = "file :/ /"
/ / + Environment.getExternalStorageDirectory (). GetPath ()
/ / + "/ DCIM / Camera /";
String b = "/ mnt / sdcard /";
File baseFile = new File (b + "dcim / Camera /");

/ / Uri uri = Uri.fromFile (baseFile);
/ / Uri uri = Uri.parse (b);
/ / Read the SD card all the pictures
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String [] projection = {MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE};
"? =" String selection = MediaStore.Images.Media.MIME_TYPE +;
String [] selectionArg = {"image / jpeg"};
Cursor mCursor = this.managedQuery (uri, projection, selection,
selectionArg, MediaStore.Images.Media.DATE_MODIFIED + "desc");
imageList.clear ();
if (mCursor! = null) {
mCursor.moveToFirst ();
while (mCursor.getPosition ()! = mCursor.getCount ()) {
imageMap = new HashMap ();
imageMap.put (imageID, mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media._ID)));
imageMap.put (imageName, mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media.DISPLAY_NAME)));
imageMap.put (
imageInfo,
""
+ (MCursor.getLong (mCursor
. GetColumnIndex (MediaStore.Images.Media.SIZE)) / 1024)
+ "KB");
imageList.add (imageMap);
fileNames.add (mCursor.getString (mCursor
. GetColumnIndex (MediaStore.Images.Media.DATA)));
mCursor.moveToNext ();
}
mCursor.close ();
}
return imageList;
}

/ / Read the SD card all the pictures
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

The way to get all the pictures no problem, but I changed to the specified folder path SD card but not

String a = "file :/ /" + Environment.getExternalStorageDirectory () getPath () + "/ dcim / Camera /";.
/ / File baseFile = new File (a + "/ dcim/Camera/15.jpg");

/ / Uri uri = Uri.fromFile (baseFile);
Uri uri = Uri.parse (a);
Reply:
For example there are two directories sdcard/Music/Music-1 and / sdcard/Music/Music-2 how to get the file structure from Music-1 directory uri?
I know that you can use to get all MediaStore.Audio.Media.EXTERNAL_CONTENT_UR external storage content, but how to get the file in a specific directory it?
Reply:
After the first empty the folder before deleting the folder.
Reply:
The landlord, the question of how to resolve the specified folder, ah, I have the same problem
Reply:
reference to the 12th floor chaozhung reply:
landlord, the question of how to resolve the specified folder, ah, I have the same problem
< br />
The same question. . .

No comments:

Post a Comment