こんにちは、私はアンドロイドの初心者&がこの修正の下に落ちていました。特定のパスを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;
}
}
フィルタリングを実行する 'WHERE'節を作成し、現在' null'を提供している 'managedQuery()'に 'WHERE'節を供給する必要があります。 – CommonsWare
これについてのあなたの迅速な対応に感謝します。あなたが除外したいフォルダが "/ mnt/sdcard/folder"とそのサブフォルダであれば、where句がuriをフィルタリングするためにどのように供給されるのか教えてください。どうもありがとう。 – Vivek