List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:com.safecell.HomeScreenActivity.java
Bitmap getImageFromURI(Uri uri) { Bitmap resizedBitmap = null;//from w ww . j a v a2 s. c om String abc = null; if (uri != null) { String str = uri.toString(); abc = str.substring(0, 1); // Log.v("Safecell :" + "abc", str); } if (uri != null && abc.equalsIgnoreCase("c")) { Uri selectedImage = uri; // Log.v("Safecell :" + "Uri", selectedImage.toString()); String[] proj = { MediaColumns.DATA }; Cursor cursor = managedQuery(selectedImage, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); cursor.moveToFirst(); String path = cursor.getString(column_index); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; resizedBitmap = BitmapFactory.decodeFile(path, options); imageStoreInDatabase(resizedBitmap); cursor.close(); return resizedBitmap; } else if (uri != null && abc.equalsIgnoreCase("/")) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; resizedBitmap = BitmapFactory.decodeFile(uri.getPath(), options); imageStoreInDatabase(resizedBitmap); return resizedBitmap; } return resizedBitmap; }
From source file:com.liangxun.yuejiula.huanxin.chat.activity.ChatActivity.java
/** * ??//from w w w . j a v a 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()) { 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.parttime.IM.ChatActivity.java
/** * ??//from w w w . ja va2 s . c om * * @param uri 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.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); // ?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:cn.hbm.superwechat.activity.ChatActivity.java
/** * ??/*w ww .jav a 2 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); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:cn.ucai.chatuidemo.activity.ChatActivity.java
/** * ??/*from www.ja v a 2 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_LONG).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_LONG).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:com.eason.marker.emchat.chatuidemo.activity.ChatActivity.java
/** * ??//from w ww .j a v a 2 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); GreenToast.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); GreenToast.makeText(getApplicationContext(), st6, 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:com.hanyu.desheng.activity.ChatActivity.java
/** * ??//from w ww .j av a 2 s .c om * * @param uri */ @SuppressLint("ShowToast") 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); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:cn.kangeqiu.kq.activity.ChatActivity.java
/** * ?uri??/*from ww w . j av a 2 s .c o m*/ * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); String st8 = getResources().getString(R.string.cant_find_pictures); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(file.getAbsolutePath()); } }
From source file:com.ieeton.agency.activity.ChatActivity.java
/** * ??/*www .java2 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()) { 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); addPitient(); setResult(RESULT_OK); }
From source file:com.android.mms.ui.MessageUtils.java
public static String getContentType(Uri uri) { String path = uri.getPath(); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(path).toLowerCase(); if (TextUtils.isEmpty(extension)) { int dotPos = path.lastIndexOf('.'); if (0 <= dotPos) { extension = path.substring(dotPos + 1); extension = extension.toLowerCase(); }//from w w w . j av a2s .c o m } String type = mimeTypeMap.getMimeTypeFromExtension(extension); return type; }