List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
public String getPath(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try {/* ww w . ja v a 2 s .co m*/ cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.blueshit.activity.ChatActivity.java
/** * ??// w w w. j a v a2 s. c o m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(R.string.File_does_not_exist); Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m); Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.easemob.ui.ChatActivity.java
/** * ??//from w ww . jav a 2 s. c o m * @param videoUri */ private void sendVideoMsg(Uri videoUri) { String[] proj = { MediaStore.Images.Media.DATA, MediaStore.Video.Media.DURATION }; try { Cursor cursor = getContentResolver().query(videoUri, proj, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); String videoPath = cursor.getString(index); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } File videoFile = new File(videoPath); System.out.println("length:" + videoFile.length()); // ???10M if (videoFile.length() > 1024 * 1024 * 10) { Toast.makeText(this, "??10M?", Toast.LENGTH_SHORT).show(); return; } // get the thumb image file File file = new File(PathUtil.getInstance().getVideoPath(), "th" + videoFile.getName()); try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file)); } catch (Exception e) { e.printStackTrace(); } sendVideo(videoPath, file.getAbsolutePath(), duration); } } else { File videoFile = new File(videoUri.getPath()); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoFile.getAbsolutePath(), 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } System.out.println("length:" + videoFile.length()); // ???10M if (videoFile.length() > 1024 * 1024 * 10) { Toast.makeText(this, "??10M?", Toast.LENGTH_SHORT).show(); return; } // get the thumb image file File file = new File(PathUtil.getInstance().getVideoPath(), "th" + videoFile.getName()); try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file)); } catch (Exception e) { e.printStackTrace(); } sendVideo(videoFile.getAbsolutePath(), file.getAbsolutePath(), 0); } } catch (Exception e) { System.out.println("exception:" + e.getMessage()); } }
From source file:com.givon.anhao.activity.ChatActivity.java
/** * ??//from ww w .j ava 2 s . c o m * * @param uri */ private void sendFile(Uri uri) { addFriend(mUserBean, chatType); String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(initExtValue(message)); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.ccxt.whl.activity.ChatActivity.java
/** * ??//from w w w . j a va 2 s. c om * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
public String getRealPathFromURI(Uri contentUri) { String res = null;// ww w . j a va2 s .c o m String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null); if (cursor.moveToFirst()) { ; int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); } cursor.close(); return res; }
From source file:com.ieeton.user.activity.ChatActivity.java
/** * ??/*from w ww.jav a 2 s . co m*/ * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", Toast.LENGTH_SHORT).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java
/** * Translates a content URI of an image to a physical path on the disk * /* w w w.j a v a 2 s.co m*/ * @param uri The URI to resolve * @return The path to the image or null if it could not be found */ public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } return null; }
From source file:com.erhuoapp.erhuo.activity.ChatActivity.java
/** * ??//from w w w . j a va 2 s .co m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(R.string.File_does_not_exist); Toast.makeText(getApplicationContext(), st7, 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m); Toast.makeText(getApplicationContext(), st6, 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); EntityUserInfo userInfo = AppUtil.getInstance().getBasicUserInfo(); message.setAttribute("from", userInfo.getNickName()); message.setAttribute("fromheader", userInfo.getHeader()); message.setAttribute("fromid", userInfo.getId()); String id = getIntent().getStringExtra("userId"); HeadAndName mHeadAndName = new HeadAndName(this); UserHeadAndName mUserHeadAndName = mHeadAndName.selectOne(id); message.setAttribute("to", mUserHeadAndName.getNick()); message.setAttribute("toheader", mUserHeadAndName.getHead()); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.android.email.mail.store.LocalStore.java
/** * When upgrading from 22 to 23, we have to move any flags "X_DOWNLOADED_FULL" or * "X_DOWNLOADED_PARTIAL" or "DELETED" from the old string-based storage to their own columns. * * Note: Caller should open a db transaction around this *//*from w ww . java 2 s . c o m*/ private void migrateMessageFlags() { Cursor cursor = mDb.query("messages", new String[] { "id", "flags" }, null, null, null, null, null); try { int columnId = cursor.getColumnIndexOrThrow("id"); int columnFlags = cursor.getColumnIndexOrThrow("flags"); while (cursor.moveToNext()) { String oldFlags = cursor.getString(columnFlags); ContentValues values = new ContentValues(); int newFlagDlFull = 0; int newFlagDlPartial = 0; int newFlagDeleted = 0; if (oldFlags != null) { if (oldFlags.contains(Flag.X_DOWNLOADED_FULL.toString())) { newFlagDlFull = 1; } if (oldFlags.contains(Flag.X_DOWNLOADED_PARTIAL.toString())) { newFlagDlPartial = 1; } if (oldFlags.contains(Flag.DELETED.toString())) { newFlagDeleted = 1; } } // Always commit the new flags. // Note: We don't have to pay the cost of rewriting the old string, // because the old flag will be ignored, and will eventually be overwritten // anyway. values.put("flag_downloaded_full", newFlagDlFull); values.put("flag_downloaded_partial", newFlagDlPartial); values.put("flag_deleted", newFlagDeleted); int rowId = cursor.getInt(columnId); mDb.update("messages", values, "id=" + rowId, null); } } finally { cursor.close(); } }