2011-08-21 23 views
1

我的要求是從日期條目中讀取輸入以在特定日期範圍內搜索圖像。
到目前爲止,我剛剛創建了一個圖庫視圖來檢索圖像文件夾中的所有圖像。
我有的代碼是給定的。在某些情況下顯示來自圖庫的選定圖像

如何在只顯示滿足條件的圖像的圖像文件夾的縮略圖之前創建條件?

public void image_search(String st) 
{ 
    Intent intent = new Intent(); 
    intent.setType("image/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, 
    "Select Picture"), SELECT_PICTURE); 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK) { 
     if (requestCode == SELECT_PICTURE) { 
      Uri selectedImageUri = data.getData(); 

      //OI FILE Manager 
      filemanagerstring = selectedImageUri.getPath(); 

      //MEDIA GALLERY 
      selectedImagePath = getPath(selectedImageUri); 

      Intent intent = new Intent(); 
      intent.setAction(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.parse("file://" + selectedImagePath), "image/*"); 
      startActivity(intent); 
     } 
    } 
} 

//UPDATED! 
public String getPath(Uri uri) { 
    String selectedImagePath; 
    //1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA 
    String[] projection = { MediaStore.Images.Media.DATA }; 
    Cursor cursor = managedQuery(uri, projection, null, null, null); 
    if(cursor != null){ 
     int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     cursor.moveToFirst(); 
     selectedImagePath = cursor.getString(column_index); 
    }else{ 
     selectedImagePath = null; 
    } 

    if(selectedImagePath == null){ 
     //2:OI FILE Manager --- call method: uri.getPath() 
     selectedImagePath = uri.getPath(); 
    } 
    return selectedImagePath; 
} 
+0

有什麼條件? – Ronnie

回答

0

如果你的意思是文件類型條件,那麼你可以簡單地設置對文件類型你想要的。
intent.setType("image/png");只能獲取PNG圖像。

編輯:
您應該實現FileFilter接口來獲取滿足您的條件的列表文件。你可以從這個列表中創建thumnails。

File imagesDir = // the File obj of directory containing image files. 
File[] imagelist = imagesDir.listFiles(new FileFilter { 

    @override 
    public boolean accept(File file) 
    { 
    // return true if this file meets ur conditions(file.length and file.lastmodified()) 
    } 

} 
+0

嗨,謝謝你的回覆。條件就像檢查修改日期或文件大小。也就是說,應該在某個特定的範圍內。 – AryA

+0

我編輯了我的答案.. – Ronnie

相關問題