List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:com.rp.justcast.video.VideoProvider.java
public static List<MediaInfo> buildMedia() throws JSONException { if (null != mediaList) { return mediaList; }//from ww w . ja v a2s .c o m String[] columns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE, MediaStore.Video.Media.DURATION }; String orderBy = MediaStore.Images.Media.DATE_TAKEN + " desc"; Cursor videoCursor = null; try { videoCursor = JustCast.getmAppContext().getContentResolver() .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy); videoCursor.moveToFirst(); long fileId = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media._ID)); Log.w(TAG, "Building Media"); Log.w(TAG, "Video Count" + videoCursor.getCount()); int count = videoCursor.getCount(); Log.d(TAG, "Count of images" + count); mediaList = new ArrayList<MediaInfo>(); for (int i = 0; i < count; i++) { videoCursor.moveToPosition(i); int dataColumnIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA); int titleIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.TITLE); Log.w(TAG, "Video added" + videoCursor.getString(dataColumnIndex)); String path = videoCursor.getString(dataColumnIndex); String title = videoCursor.getString(titleIndex); MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString("VIDEO_PATH", path); movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, title); movieMetadata.putString(MediaMetadata.KEY_TITLE, title); movieMetadata.putString(MediaMetadata.KEY_STUDIO, title); path = JustCast.addJustCastServerParam(path); MediaInfo mediaInfo = new MediaInfo.Builder(path).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType(getMediaType()).setMetadata(movieMetadata).build(); mediaList.add(mediaInfo); } } finally { videoCursor.close(); } return mediaList; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *//*from w w w . j a va 2 s . c om*/ @SuppressWarnings("deprecation") public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:io.trigger.forge.android.modules.contprov.API.java
private static JSONArray extractNotesFromCursor(Cursor c) throws JSONException { JSONArray toRet = new JSONArray(); int[] cIndices = new int[] { c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_2_catname), c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_3_catstatus) }; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {//Extract note from cursor JSONObject o = new JSONObject(); o.put("name", c.getString(cIndices[0])); o.put("status", c.getString(cIndices[1])); //c.getString(cIndices[SERVER_ID]), toRet.put(o);// w w w .j a v a 2 s .com } return toRet; }
From source file:Main.java
/** * Using code from this link: http://hmkcode.com/android-display-selected-image-and-its-real-path/ * This method will return the absolute path Android.net.Uri. * NOTE!!! THIS DOES NOT SUPPORT API 10 OR BELOW!!! IF YOU NEED TO WORK WITH THAT, CHECK LINK ABOVE * @param context Context//from w w w . j a va 2s . com * @param uri Uri to check * @return String for the absolute path */ public static String getAbsolutePath(Context context, android.net.Uri uri) { if (Build.VERSION.SDK_INT >= 19) { try { String filePath = ""; String wholeID = DocumentsContract.getDocumentId(uri); // Split at colon, use second item in the array String id = wholeID.split(":")[1]; String[] column = { MediaStore.Images.Media.DATA }; // where id is equal to String sel = MediaStore.Images.Media._ID + "=?"; Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[] { id }, null); int columnIndex = cursor.getColumnIndex(column[0]); if (cursor.moveToFirst()) { filePath = cursor.getString(columnIndex); } cursor.close(); return filePath; } catch (Exception e) { e.printStackTrace(); return null; } } else { try { String[] proj = { MediaStore.Images.Media.DATA }; String result = null; CursorLoader cursorLoader = new CursorLoader(context, uri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); result = cursor.getString(column_index); } return result; } catch (Exception e) { e.printStackTrace(); return null; } } }
From source file:Main.java
public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null;/* w w w . java 2 s .c o m*/ if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {//from w w w .j a va2 s. com cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
protected static String getImagePath(Uri imageUri, Context context) { String scheme = imageUri.getScheme(); if (scheme.equals("file")) return imageUri.getPath(); Cursor cursor = null; try {//from www. j a v a 2 s.c o m String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(imageUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) cursor.close(); } }
From source file:com.whiuk.philip.opensmime.PathConverter.java
private static FileInformation handleContentScheme(Context context, Uri uri) { try {/*from w ww . j a v a 2 s . c o m*/ ContentResolver contentResolver = context.getContentResolver(); // all fields for one document Cursor cursor = contentResolver.query(uri, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is // provider-specific, and might not necessarily be the file name. String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); String mimeType = cursor .getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); InputStream stream = contentResolver.openInputStream(uri); File tmpFile = copyToTempFile(context, stream); return new FileInformation(tmpFile, displayName, mimeType); } } catch (IOException e) { Log.e(OpenSMIME.LOG_TAG, "error in PathConverter.handleContentScheme", e); } return null; }
From source file:de.fau.cs.mad.smile.android.encryption.PathConverter.java
private static FileInformation handleContentScheme(Context context, Uri uri) { try {/*from ww w.jav a 2 s .com*/ ContentResolver contentResolver = context.getContentResolver(); // all fields for one document Cursor cursor = contentResolver.query(uri, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is // provider-specific, and might not necessarily be the file name. String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); String mimeType = cursor .getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); InputStream stream = contentResolver.openInputStream(uri); File tmpFile = copyToTempFile(context, stream); return new FileInformation(tmpFile, displayName, mimeType); } } catch (IOException e) { Log.e(SMileCrypto.LOG_TAG, "error in PathConverter.handleContentScheme", e); } return null; }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = MediaStore.Images.Media.DATA; final String[] projection = { column }; try {/*w w w. ja v a2s . com*/ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; }