List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:fi.mikuz.boarder.gui.internet.InternetMenu.java
protected String getUsername() { String username = null;//from w w w . j a va 2 s .c om try { Cursor loginCursor = mDbHelper.fetchLogin(InternetMenu.USERNAME_KEY); startManagingCursor(loginCursor); username = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA)); } catch (SQLException e) { Log.d(TAG, "Couldn't get database login info", e); } return username; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static ECMessage getLastECMessage() { int maxVersion = getMaxVersion(); String sql = "select im_message.* ,im_thread.sessionId from im_message ,im_thread where version = " + maxVersion + " and im_message.sid=im_thread.id"; Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { ECMessage ecMessage = packageMessage(cursor); String sessionid = cursor.getString(cursor.getColumnIndexOrThrow(IThreadColumn.THREAD_ID)); ecMessage.setSessionId(sessionid); cursor.close();//from w w w.j ava 2s. c o m if (ecMessage != null) { return ecMessage; } } } return null; }
From source file:com.navjagpal.fileshare.WebServer.java
private String getFileListing(Uri uri) { int folderId = Integer.parseInt(uri.getPathSegments().get(1)); Uri fileUri = FileSharingProvider.Files.CONTENT_URI; String where = FileSharingProvider.Files.Columns.FOLDER_ID + "=" + folderId; Cursor c = mContext.getContentResolver().query(fileUri, null, where, null, null); int nameIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns.DISPLAY_NAME); int idIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns._ID); String s = ""; boolean hasMusic = false; while (c.moveToNext()) { String name = c.getString(nameIndex); int id = c.getInt(idIndex); s += fileToLink(name, id) + "<br/>"; if (name.endsWith(".mp3")) { hasMusic = true;//from ww w .ja v a 2 s.c o m } } c.close(); if (hasMusic) { s += getPlaylistLink(folderId) + "<br/>"; } s += getZipLink(folderId) + "<br/>"; return s; }
From source file:com.cbtec.eliademy.EliademyLms.java
/** * Called when an activity you launched exits, giving you the requestCode * you started it with, the resultCode it returned, and any additional data * from it./*w w w .j a va 2 s.c o m*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param data * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case submitFileCode: if (resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); uri = Uri.parse(cursor.getString(column_index)); } } if (this.mCallbackContext != null) { this.mCallbackContext.success(uri.toString()); return; } else { Log.i("HLMS", "callback context is null"); } } break; } if (this.mCallbackContext != null) { this.mCallbackContext.error(resultCode); } else { Log.i("HLMS", "callback context is null"); } }
From source file:com.bitants.wally.fragments.SavedImagesFragment.java
public String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try {/*from w ww .j a va2s .c om*/ String[] projection = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, projection, 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.haru.ui.image.workers.MediaProcessorThread.java
@SuppressLint("NewApi") protected String getAbsoluteImagePathFromUri(Uri imageUri) { String[] proj = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME }; if (/* TODO: DEBUG */ true) { Log.i(TAG, "Image Uri: " + imageUri.toString()); }/*from w w w. j a v a 2 s . c om*/ if (imageUri.toString().startsWith("content://com.android.gallery3d.provider")) { imageUri = Uri .parse(imageUri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d")); } String filePath = ""; String imageUriString = imageUri.toString(); if (imageUriString.startsWith("content://com.google.android.gallery3d") || imageUriString.startsWith("content://com.google.android.apps.photos.content") || imageUriString.startsWith("content://com.android.providers.media.documents") || imageUriString.startsWith("content://com.google.android.apps.docs.storage") || imageUriString.startsWith("content://com.microsoft.skydrive.content.external")) { filePath = imageUri.toString(); } else { Cursor cursor = context.getContentResolver().query(imageUri, proj, null, null, null); cursor.moveToFirst(); filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA)); cursor.close(); } return filePath; }
From source file:com.snail.imagechooser.threads.MediaProcessorThread.java
@SuppressLint("NewApi") protected String getAbsoluteImagePathFromUri(Uri imageUri) { String[] proj = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME }; if (Config.DEBUG) { Log.i(TAG, "Image Uri: " + imageUri.toString()); }// w ww. ja v a 2 s . c om if (imageUri.toString().startsWith("content://com.android.gallery3d.provider")) { imageUri = Uri .parse(imageUri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d")); } String filePath = ""; String imageUriString = imageUri.toString(); if (imageUriString.startsWith("content://com.google.android.gallery3d") || imageUriString.startsWith("content://com.google.android.apps.photos.content") || imageUriString.startsWith("content://com.android.providers.media.documents") || imageUriString.startsWith("content://com.google.android.apps.docs.storage") || imageUriString.startsWith("content://com.microsoft.skydrive.content.external")) { filePath = imageUri.toString(); } else { Cursor cursor = context.getContentResolver().query(imageUri, proj, null, null, null); cursor.moveToFirst(); filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA)); cursor.close(); } return filePath; }
From source file:rpassmore.app.fillthathole.ViewHazardActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case PICK_PHOTO_ACTIVITY: { if (resultCode == RESULT_OK) { Bitmap bitmap;/* w w w . j av a 2 s. c o m*/ try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData())); storeNewPhoto(bitmap, data.getData().toString()); } catch (FileNotFoundException ex) { Log.e(getPackageName(), "Error loading image file", ex); } } break; } case PICTURE_ACTIVITY: { if (resultCode == RESULT_OK) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(capturedImageURI, projection, null, null, null); int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String capturedImageFilePath = cursor.getString(column_index_data); Bitmap bitmap = BitmapFactory.decodeFile(capturedImageFilePath); storeNewPhoto(bitmap, capturedImageFilePath); } break; } case LOCATION_MAP_ACTIVITY: { if (resultCode == RESULT_OK) { Bundle extras = data.getExtras(); if (extras != null) { hazard.setLattitude(extras.getLong(LocationActivity.LOCATION_LAT) / 1.0E6); hazard.setLongitude(extras.getLong(LocationActivity.LOCATION_LONG) / 1.0E6); if (extras.getString("Address") != null) { hazard.setAddress(extras.getString(LocationActivity.LOCATION_ADDRESS)); } } } break; } } }
From source file:com.navjagpal.fileshare.WebServer.java
private void addFileEntity(final Uri uri, HttpResponse response) throws IOException { if (mTransferStartedListener != null) { mTransferStartedListener.started(uri); }// w w w.j a v a2 s .c o m Cursor c = mContext.getContentResolver().query(uri, null, null, null, null); c.moveToFirst(); int nameIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns.DISPLAY_NAME); String name = c.getString(nameIndex); int dataIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns._DATA); Uri data = Uri.parse(c.getString(dataIndex)); c = mContext.getContentResolver().query(data, null, null, null, null); c.moveToFirst(); int sizeIndex = c.getColumnIndexOrThrow(OpenableColumns.SIZE); int sizeBytes = c.getInt(sizeIndex); c.close(); InputStream input = mContext.getContentResolver().openInputStream(data); String contentType = "application/octet-stream"; if (name.endsWith(".jpg")) { contentType = "image/jpg"; } response.addHeader("Content-Type", contentType); response.addHeader("Content-Length", "" + sizeBytes); response.setEntity(new InputStreamEntity(input, sizeBytes)); }
From source file:com.google.android.apps.gutenberg.EventSelectionFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { switch (loader.getId()) { case LOADER_EVENTS: { mAdapter.swapCursor(cursor);/*w w w . ja v a 2 s .c om*/ mSpinner.setOnItemSelectedListener(null); GutenbergApplication app = GutenbergApplication.from(getActivity()); String eventId = app.getEventId(); if (TextUtils.isEmpty(eventId)) { if (cursor.moveToFirst()) { eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Event.ID)); mSpinner.setSelection(0, false); app.setEventId(eventId); } } else { int position = mAdapter.findPosition(eventId); if (position >= 0) { mSpinner.setSelection(position, false); } } mAdapter.setCurrentEventId(eventId); mSpinner.setOnItemSelectedListener(this); if (cursor.getCount() == 0) { mNoEvent.setVisibility(View.VISIBLE); mSpinner.setVisibility(View.GONE); } else { mNoEvent.setVisibility(View.GONE); mSpinner.setVisibility(View.VISIBLE); } break; } } }