@Override protected ZLFile fileFromIntent(Intent intent) { String filePath = intent.getStringExtra(BOOK_PATH_KEY); if (filePath == null) { final Uri data = intent.getData(); if (data != null) { filePath = data.getPath(); } } return filePath != null ? ZLFile.createFileByPath(filePath) : null; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { String filePickerResult = ""; if (data != null && resultCode == RESULT_OK) { try { ContentResolver cr = getContentResolver(); Uri uri = data.getData(); Cursor cursor = GeckoApp.mAppContext .getContentResolver() .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null); String name = null; if (cursor != null) { try { if (cursor.moveToNext()) { name = cursor.getString(0); } } finally { cursor.close(); } } String fileName = "tmp_"; String fileExt = null; int period; if (name == null || (period = name.lastIndexOf('.')) == -1) { String mimeType = cr.getType(uri); fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType); } else { fileExt = name.substring(period); fileName = name.substring(0, period); } File file = File.createTempFile(fileName, fileExt, sGREDir); FileOutputStream fos = new FileOutputStream(file); InputStream is = cr.openInputStream(uri); byte[] buf = new byte[4096]; int len = is.read(buf); while (len != -1) { fos.write(buf, 0, len); len = is.read(buf); } fos.close(); filePickerResult = file.getAbsolutePath(); } catch (Exception e) { Log.e(LOG_FILE_NAME, "showing file picker", e); } } try { mFilePickerResult.put(filePickerResult); } catch (InterruptedException e) { Log.i(LOG_FILE_NAME, "error returning file picker result", e); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { // found this from StackOverflow if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else { // -----------I wrote this code below this line---------------------------------- jpegData = intent.getExtras().getByteArray("image"); Bitmap img = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); Drawable d = new BitmapDrawable(img); profilePicture.setBackground(d); } }
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { switch (requestCode) { case CAMERA_RESULT: if (TextUtils.isEmpty(content.getText().toString())) { content.setText(getString(R.string.share_pic)); content.setSelection(content.getText().toString().length()); } picPath = getPicPathFromUri(imageFileUri); havePic.setVisibility(View.VISIBLE); break; case PIC_RESULT: if (TextUtils.isEmpty(content.getText().toString())) { content.setText(getString(R.string.share_pic)); content.setSelection(content.getText().toString().length()); } Uri imageFileUri = intent.getData(); picPath = getPicPathFromUri(imageFileUri); havePic.setVisibility(View.VISIBLE); break; case AT_USER: String name = intent.getStringExtra("name"); String ori = content.getText().toString(); int index = content.getSelectionStart(); StringBuilder stringBuilder = new StringBuilder(ori); stringBuilder.insert(index, name); content.setText(stringBuilder.toString()); content.setSelection(index + name.length()); break; } } }