List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
private 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. ja va2s . c om*/ 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:com.example.zf_android.trade.ApplyDetailActivity.java
public String getRealPathFromURI(Uri contentUri) { try {//from www.j a v a 2s .co m String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = this.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } catch (Exception e) { return contentUri.getPath(); } }
From source file:com.gsma.rcs.ri.messaging.OneToOneTalkView.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); Cursor cursor = (Cursor) (mAdapter.getItem(info.position)); int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID)); String id = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID)); if (LogUtils.isActive) { Log.d(LOGTAG, "onContextItemSelected Id=".concat(id)); }/*from w ww .j av a 2 s . c o m*/ try { switch (item.getItemId()) { case R.id.menu_delete_message: switch (providerId) { case ChatLog.Message.HISTORYLOG_MEMBER_ID: mChatService.deleteMessage(id); return true; case FileTransferLog.HISTORYLOG_MEMBER_ID: mFileTransferService.deleteFileTransfer(id); return true; } break; case R.id.menu_resend_message: switch (providerId) { case ChatLog.Message.HISTORYLOG_MEMBER_ID: OneToOneChat chat = mChatService.getOneToOneChat(mContact); if (chat != null) { chat.resendMessage(id); } return true; case FileTransferLog.HISTORYLOG_MEMBER_ID: FileTransfer fileTransfer = mFileTransferService.getFileTransfer(id); if (fileTransfer != null) { fileTransfer.resendTransfer(); } return true; } break; case R.id.menu_display_content: switch (providerId) { case FileTransferLog.HISTORYLOG_MEMBER_ID: String file = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.CONTENT)); Utils.showPicture(this, Uri.parse(file)); markFileTransferAsRead(cursor, id); return true; } break; case R.id.menu_view_detail: switch (providerId) { case ChatLog.Message.HISTORYLOG_MEMBER_ID: ChatMessageLogView.startActivity(this, id); return true; case FileTransferLog.HISTORYLOG_MEMBER_ID: FileTransferLogView.startActivity(this, id); return true; } break; case R.id.menu_listen_content: if (FileTransferLog.HISTORYLOG_MEMBER_ID == providerId) { String file = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.CONTENT)); Utils.playAudio(this, Uri.parse(file)); markFileTransferAsRead(cursor, id); return true; } break; } return super.onContextItemSelected(item); } catch (RcsGenericException | RcsPermissionDeniedException | RcsPersistentStorageException e) { showException(e); return true; } catch (RcsServiceNotAvailableException e) { Utils.displayLongToast(this, getString(R.string.label_service_not_available)); return true; } }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
private String getImagePath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if (cursor == null) return null; int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); String path = null;//from w w w .j a va2 s . c o m if (cursor.moveToFirst()) { path = cursor.getString(column_index); } return path; }
From source file:org.mythtv.service.content.v25.LiveStreamHelperV25.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV25 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);//from ww w .java2s .c o m String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
From source file:org.mythtv.service.content.v26.LiveStreamHelperV26.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV26 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);/*from w w w. j a va 2s .c om*/ String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
From source file:org.mythtv.service.content.v27.LiveStreamHelperV27.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV27 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);//from w ww . ja v a 2 s . c om String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
From source file:com.anyonavinfo.commonuserregister.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); String content = bundle.getString("result"); // ??/*from w w w.ja v a2 s . c o m*/ if (!StringUtils.isEmpty(content)) { edittext_userVin.setText(content); } } else if (requestCode == 2 && resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); String shopId = bundle.getString("ID"); String shopName = bundle.getString("NAME"); //Log.d("shopId", shopId); edittext_userOrgId.setText(shopName); orgId = shopId; } else if (requestCode == 3 && resultCode == RESULT_OK) { /** * ??? */ Uri uri = data.getData(); Log.e("Sjj--->", "uri = " + uri); BitmapFactory.Options options = new BitmapFactory.Options(); // options.inJustDecodeBoundstrue options.inJustDecodeBounds = true; options.inPreferredConfig = Bitmap.Config.RGB_565; // Bitmap.Config.ARGB_8888 try { //???? Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); // options.inJustDecodeBounds?false options.inJustDecodeBounds = false; int w = options.outWidth; int h = options.outHeight; Log.i("path", "" + w + "" + h); float hh = 800f;//800f float ww = 480f;//480f //???? int be = 1;//be=1? if (w > h && w > ww) {//??? be = (int) (options.outWidth / ww); } else if (w < h && h > hh) {//??? be = (int) (options.outHeight / hh); } if (be <= 0) be = 1; options.inSampleSize = be;// Log.d("Size", be + ""); //? Bitmap bitmapSize = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); Log.d("sizePic", bitmapSize.getWidth() + "" + bitmapSize.getHeight()); /** * ??????? * ?picPath=path,:???Uri?cursor * ?uri??url */ Uri sizePicUrl = Uri .parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmapSize, null, null)); Log.d("sizePicUrl", sizePicUrl + ""); String[] pojoSizePic = { MediaStore.Images.Media.DATA }; Cursor cursorSizePic = managedQuery(sizePicUrl, pojoSizePic, null, null, null); if (cursorSizePic != null) { //ContentResolver cr = this.getContentResolver(); int colunm_index = cursorSizePic.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursorSizePic.moveToFirst(); String pathSizePic = cursorSizePic.getString(colunm_index); picPath = pathSizePic; } /*********************************************************************************************/ String[] pojo = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, pojo, null, null, null); if (cursor != null) { //ContentResolver cr = this.getContentResolver(); int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String path = cursor.getString(colunm_index); Log.d("path", path); /*** * ???? * ???? ???? */ if (path.endsWith("jpg") || path.endsWith("png")) { //picPath = path; // Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); userPictureRight.setImageBitmap(bitmapSize); } else { alert(); } } else { alert(); } } catch (Exception e) { } } }
From source file:com.cattle.util.CursorPagerAdapter.java
/** * Swap in a new Cursor, returning the old Cursor. Unlike {@link #changeCursor(android.database.Cursor)}, the * returned old Cursor is <em>not</em> closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there was not one. If the given new Cursor * is the same instance is the previously set Cursor, null is also returned. *//*from w w w. j a va 2 s .co m*/ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) { oldCursor.unregisterContentObserver(mChangeObserver); } if (mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) { newCursor.registerContentObserver(mChangeObserver); } if (mDataSetObserver != null) { newCursor.registerDataSetObserver(mDataSetObserver); } mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); } return oldCursor; }
From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java
public void processProgram(final Context context, final LocationProfile locationProfile, Uri uri, String table, ArrayList<ContentProviderOperation> ops, Program program, String tag) { // Log.d( TAG, "processProgram : enter" ); ContentValues programValues = convertProgramToContentValues(locationProfile, program, tag); if (table.equals(ProgramConstants.TABLE_NAME_RECORDED) || table.equals(ProgramConstants.TABLE_NAME_UPCOMING) || table.equals(ProgramConstants.TABLE_NAME_GUIDE)) { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build());//from w ww . j a v a2 s. co m } else { String programSelection = table + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND " + table + "." + ProgramConstants.FIELD_START_TIME + " = ?"; String[] programSelectionArgs = new String[] { String.valueOf(program.getChannel().getChanId()), String.valueOf(program.getStartTime().getMillis()) }; programSelection = appendLocationHostname(context, locationProfile, programSelection, table); Cursor programCursor = context.getContentResolver().query(uri, programProjection, programSelection, programSelectionArgs, null); if (programCursor.moveToFirst()) { Log.v(TAG, "processProgram : UPDATE PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table); Long id = programCursor.getLong(programCursor.getColumnIndexOrThrow(ProgramConstants._ID)); ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(uri, id)) .withValues(programValues).withYieldAllowed(true).build()); } else { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build()); } programCursor.close(); } // Log.d( TAG, "processProgram : exit" ); }