我的應用程序當前保存到我指定的文件夾/Pictures/<app_name>/
,但它也保存到默認文件夾/DCIM/Camera/
。這導致文件被保存到SD卡兩次,但在不同的文件夾中。我如何製作它,因此它不會將它保存到兩個文件夾,只有我指定的文件夾?如何更改SD卡保存到的默認文件夾?
2
A
回答
2
答案已經得到Here。
只要到原來的答案--->HERE THE SOLUTION
我剛纔添加的解決方案,以避免如果鏈接的頁面變化的無效答案。
檢查下面的代碼:
private void FillPhotoList() {
// initialize the list!
GalleryList.clear();
String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME };
for(int i=0;i<projection.length;i++)
Log.i("InfoLog","projection "+projection[0].toString());
// intialize the Uri and the Cursor, and the current expected size.
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","FillPhoto Uri u "+u.toString());
// Query the Uri to get the data path. Only if the Uri is valid.
if (u != null)
{
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the id).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Loop each and add to the list.
GalleryList.add(c.getString(0)); // adding all the images sotred in the mobile phone(Internal and SD card)
}
while (c.moveToNext());
}
Log.i(INFOLOG,"gallery size "+ GalleryList.size());
}
而這正是該方法是做所有的魔法
/** Method will check all the photo is the gallery and delete last captured and move it to the required folder.
*/
public void movingCapturedImageFromDCIMtoMerchandising()
{
// This is ##### ridiculous. Some versions of Android save
// to the MediaStore as well. Not sure why! We don't know what
// name Android will give either, so we get to search for this
// manually and remove it.
String[] projection = { MediaStore.Images.ImageColumns.SIZE,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATA,
BaseColumns._ID,};
// intialize the Uri and the Cursor, and the current expected size.
for(int i=0;i<projection.length;i++)
Log.i("InfoLog","on activityresult projection "+projection[i]);
//+" "+projection[1]+" "+projection[2]+" "+projection[3] this will be needed if u remove the for loop
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","on activityresult Uri u "+u.toString());
if (CurrentFile != null)
{
// Query the Uri to get the data path. Only if the Uri is valid,
// and we had a valid size to be searching for.
if ((u != null) && (CurrentFile.length() > 0))
{
//****u is the place from data will come and projection is the specified data what we want
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the size).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Check each area in the gallery we built before.
boolean bFound = false;
for (String sGallery : GalleryList)
{
if (sGallery.equalsIgnoreCase(c.getString(1)))
{
bFound = true;
Log.i("InfoLog","c.getString(1) "+c.getString(1));
break;
}
}
// To here we looped the full gallery.
if (!bFound) //the file which is newly created and it has to be deleted from the gallery
{
// This is the NEW image. If the size is bigger, copy it.
// Then delete it!
File f = new File(c.getString(2));
// Ensure it's there, check size, and delete!
if ((f.exists()) && (CurrentFile.length() < c.getLong(0)) && (CurrentFile.delete()))
{
// Finally we can stop the copy.
try
{
CurrentFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(f).getChannel();
destination = new FileOutputStream(CurrentFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally
{
if (source != null)
{
source.close();
}
if (destination != null)
{
destination.close();
}
}
}
catch (IOException e)
{
// Could not copy the file over.
ToastMaker.makeToast(this, "Error Occured", 0);
}
}
//****deleting the file which is in the gallery
Log.i(INFOLOG,"imagePreORNext1 "+imagePreORNext);
Handler handler = new Handler();
//handler.postDelayed(runnable,300);
Log.i(INFOLOG,"imagePreORNext2 "+imagePreORNext);
ContentResolver cr = getContentResolver();
cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, BaseColumns._ID + "=" + c.getString(3), null);
break;
}
}
while (c.moveToNext());
}
}
}
1
對於Android的薑餅版本2.3.3,您可以更改攝像頭默認保存位置。啓動相機應用程序,單擊設置(cog),單擊扳手選項卡,向下滾動,然後選擇存儲卡。更改爲存儲卡(與內部存儲器相比)。
相關問題
- 1. 保存文件到SD卡
- 2. 如何保存文件到SD卡
- 3. 如何將文件保存到SD卡?
- 4. 如何更改默認文件夾
- 5. 如何保存SD卡中的文件?
- 6. 將視頻文件保存到SD卡文件夾
- 7. NanoHTTPD如何將上傳的文件保存到SD卡文件夾
- 8. 將文本文件保存到SD卡
- 9. 安卓:影像保存到特定的文件夾在SD卡
- 10. 默認「保存的遊戲」文件夾
- 11. 如何將音樂文件從原始文件夾保存到SD卡中android
- 12. 保存到SD卡
- 13. Android:將文件保存到SD卡?
- 14. 將文件保存到SD卡
- 15. Android:將文件保存到SD卡
- 16. Android:將文件保存到SD卡
- 17. 如何更改保存PStore文件的默認根目錄?
- 18. 更改默認文件夾的Apache
- 19. 將圖像保存到SD卡文件夾
- 20. 如何獲取Android上的SD卡上的默認圖片文件夾?
- 21. Apache FOP更改默認緩存文件文件夾
- 22. 用setuptools更改默認dist文件夾
- 23. 更改默認文件夾權限ubuntu
- 24. USB文件夾和SD卡文件夾
- 25. 鏈接到SD卡中的文件夾
- 26. 如何將文件從網站保存到SD卡
- 27. 在Android上保存文件,但不保存到SD卡
- 28. SD卡新建文件夾
- 29. 如何更改Flash Builder的默認src文件夾名稱
- 30. 如何更改默認的Eclipse WTP「Web Resources」動態文件夾
我真的不明白那個方法試圖做什麼。我用這個,而不是它幫助http://stackoverflow.com/questions/8563570/double-save-image – Neeta 2011-12-23 22:08:58