2011-10-18 2 views
0

こんにちは、私はアンドロイドの初心者&がこの修正の下に落ちていました。特定のパスをmanageQuery usigカーソル経由で検索から除外する方法android

私は、デバイスのSDカードに保存されているすべてのビデオ(mp4形式)を検索することになっています。ここに私が付いている必要がある唯一の条件は、それは指定されたフォルダ&サブの子を見てはならないが、他のものだけを調べるべきではないということです。これまでのところ、除外されるフォルダを含むSDカードに保存されたすべての動画の結果が表示されます。これが達成されたら、私はサムネイル&からファイルを選択して、そのパス&がそれ以上の操作を実行するようにしなければなりませんでした。 Uriが指定したコンテンツから特定のパスを除外するにはどうすればよいですか?以下は私のコードです

この点に関するお手伝いをさせていただきます。

参考のために私もこのクエリを調べましたDisplay video files in listview from sdcard folder しかし、残念ながら私はmanagedQueryのコンセプトに固執しなければならないので、残念ながら私の懸念を解決しませんでした。あなたの貴重な提案のための

public class BrowseActivity extends Activity { 
//set constants for MediaStore to query, and show videos 
private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 
private final static String _ID = MediaStore.Video.Media._ID; 
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA; 
private GridView galleryView; 
private Cursor cursor; 
private int columnIndex; 
private int[] videosId; 
private Uri contentUri; 

protected Context context; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    context = getApplicationContext(); 
    setContentView(R.layout.browse); 
    //set GridView for gallery 
    galleryView = (GridView) findViewById(R.id.gridview); 
    //set default as external/sdcard uri 
    contentUri = MEDIA_EXTERNAL_CONTENT_URI; 
    showToast("contentUri is---------:- "+contentUri); 
    //initialize the videos uri 
    initVideosId(); 
    //set gallery adapter 
    setGalleryAdapter(); 
} 

private void setGalleryAdapter() { 
    galleryView.setAdapter(new VideoGalleryAdapter(context)); 
    galleryView.setOnItemClickListener(_itemClickLis); 
    showToast("Gallery Adapter Set "); 
} 

private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener() { 
    public void onItemClick(AdapterView parent, View v, int position, long id) { 
     System.gc(); 
     // Now we want to actually get the data location of the file 
     String [] proj={MEDIA_DATA}; 
     // We request our cursor again 
     cursor = managedQuery(contentUri, 
       proj, // Which columns to return 
       null, // WHERE clause; which rows to return (all rows) 
       null, // WHERE clause selection arguments (none) 
       null); // Order-by clause (ascending by name) 
     // We want to get the column index for the data uri 
     // int count = cursor.getCount(); 
     cursor.moveToFirst(); 
     columnIndex = cursor.getColumnIndex(MEDIA_DATA); 
     // Lets move to the selected item in the cursor 
     cursor.moveToPosition(position); 
     String filename = cursor.getString(columnIndex); 
     showToast("Your Selection is:- "+filename); 
    } 
}; 

private void initVideosId() { 
    try {   
     //Here we set up a string array of the thumbnail ID column we want to get back 
     String [] proj={_ID}; 
     // Now we create the cursor pointing to the external thumbnail store 
     cursor = managedQuery(contentUri, 
       proj, // Which columns to return 
       null, // WHERE clause; which rows to return (all rows) 
       null, // WHERE clause selection arguments (none) 
       null); // Order-by clause (ascending by name) 
     int count= cursor.getCount(); 
     // We now get the column index of the thumbnail id 
     columnIndex = cursor.getColumnIndex(_ID); 
     videosId = new int[count]; 
     //move position to first element 
     cursor.moveToFirst(); 

     for(int i=0;i<count;i++) { 
      int id = cursor.getInt(columnIndex); 
      videosId[i]= id; 
      cursor.moveToNext(); 
     } 
    } catch(Exception ex) { 
     showToast(ex.getMessage().toString()); 
    } 
} 

protected void showToast(String msg) { 
    Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); 
} 

private class VideoGalleryAdapter extends BaseAdapter 
{ 
    public VideoGalleryAdapter(Context c) { 
     context = c; 
    } 

    public int getCount() { 
     return videosId.length; 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imgVw= new ImageView(context); 
     try { 
      if(convertView!=null) { 
       imgVw= (ImageView) convertView; 
      } 
      imgVw.setImageBitmap(getImage(videosId[position])); 
      imgVw.setLayoutParams(new GridView.LayoutParams(96, 96)); 
      imgVw.setPadding(8, 8, 8, 8); 
     } catch(Exception ex) { 
      System.out.println("BrowseActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage()); 
     } 
     return imgVw; 
    } 

    // Create the thumbnail on the fly 
    private Bitmap getImage(int id) { 
     Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
       getContentResolver(), 
       id, MediaStore.Video.Thumbnails.MICRO_KIND, null); 
     return thumb; 
    } 
} 
+0

フィルタリングを実行する 'WHERE'節を作成し、現在' null'を提供している 'managedQuery()'に 'WHERE'節を供給する必要があります。 – CommonsWare

+0

これについてのあなたの迅速な対応に感謝します。あなたが除外したいフォルダが "/ mnt/sdcard/folder"とそのサブフォルダであれば、where句がuriをフィルタリングするためにどのように供給されるのか教えてください。どうもありがとう。 – Vivek

答えて

2

おかげCommonWareが、その理由は、私は句があるサンプルのためにあなたを求めて、私だけで、私はしかしどこなど、列名などの句

で何shalli言及認識していなかったこと、この完全な努力を重ねた後、最終的には&という作品が、まさに私がやるべきことをしてくれたという例があります。今私は特定のフォルダを除くデバイスを照会することができます。 私はちょうど私がそれを共有すると思った。

私はちょうど私のクエリ内のいくつかの変更トリガさ

cursor = managedQuery(contentUri, 
      proj, 
      MediaStore.Images.Media.DATA + " not like ? ", 
      new String[] {"%excludeFolder%"}, 
      null); 

% excludeFolder%のパスを指し例を/ mnt/SDカード/ excludeFolder &そのサブ子を作りました。 また、注目すべき点は、クエリは類似していないため、これを検索から除外する点です。

しかし、これは私が達成した方法です。他にも良いオプションがある場合は、あなたの貴重な回答に依然として疑問が残っています。

* PS: - 評価してください/あなたがそれを好きならば頼みます&あなたの懸念を解決します。 *

ありがとうございました。

関連する問題