List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:br.com.GUI.avaliacoes.AvaliarPerimetria.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 200 || requestCode == 202) { if (requestCode == 200) { selectedImageUri = data.getData(); cortar(requestCode);//ww w. j av a 2 s.com } else if (requestCode == 202) { //get the returned data Bundle extras = data.getExtras(); //get the cropped bitmap Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } } else if (requestCode == 100 || requestCode == 102) { if (requestCode == 100) { selectedImageUri = data.getData(); cortar(requestCode); } else if (requestCode == 102) { Bundle extras = data.getExtras(); Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } } } else { selectedImageUri = null; } /* if(requestCode == 100){ selectedImageUri = Uri.fromFile(photo); ContentResolver cr = getActivity().getContentResolver(); Bitmap foto; try{ foto = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImageUri); bmp = ImageUtils.compactImages(foto); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); }catch(FileNotFoundException e){ Log.i("Exception", e.toString()); e.printStackTrace(); } catch (IOException e){ Log.i("Exception", e.toString()); e.printStackTrace(); } }else if( requestCode == 200){ if (resultCode == Activity.RESULT_OK) { try { Uri selectedImage = data.getData(); String[] nomeCaminho = {MediaStore.Images.Media.DATA}; Cursor cursor = getActivity().getContentResolver().query(selectedImage, nomeCaminho, null, null, null); cursor.moveToFirst(); int indexColuna = cursor.getColumnIndex(nomeCaminho[0]); String caminho = cursor.getString(indexColuna); bmp = ImageUtils.compactImages(BitmapFactory.decodeFile(caminho)); adicionarFotosPersistencia(bmp); adicionarFotosNaInterface(); } catch (Exception e) { Toast.makeText(getActivity(), "Failed to load", Toast.LENGTH_SHORT).show(); Log.e("Camera", e.toString()); } } else { selectedImageUri = null; //bmp.setImageBitmap(null); } } */ }
From source file:co.nerdart.ourss.activity.EntriesListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent(); long feedId = intent.getLongExtra(FeedColumns._ID, 0); String title = null;/*w ww . jav a 2 s.c om*/ if (feedId > 0) { Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null, null); if (cursor.moveToFirst()) { title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0); iconBytes = cursor.getBlob(2); } cursor.close(); } if (title != null) { setTitle(title); } if (savedInstanceState == null) { EntriesListFragment fragment = new EntriesListFragment(); Bundle args = new Bundle(); args.putParcelable(EntriesListFragment.ARG_URI, intent.getData()); fragment.setArguments(args); fragment.setHasOptionsMenu(true); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit(); } if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } } if (MainActivity.mNotificationManager == null) { MainActivity.mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); } }
From source file:anastasoft.rallyvision.activity.MenuPrincipal.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CHOOSER: if (resultCode == RESULT_OK) { final Uri uri = data.getData(); new CarregarArquivoCommand(aController, uri).Execute(); }/*from ww w . j a va 2s . co m*/ break; } aController.handleActivityResult(requestCode, resultCode, data); }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
private void handleImage(Intent data) { Uri uri = data.getData(); String path = getImagePath(uri); if (path == null) { showToast(getString(R.string.no_sd)); return;//from ww w. j av a2s.c om } File file = new File(path); attachPhoto(file); }
From source file:com.ximai.savingsmore.save.activity.FourStepRegisterActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode != RESULT_OK) { return;/*from w ww .j a va2 s .c o m*/ } else if (requestCode == PICK_FROM_CAMERA || requestCode == PICK_FROM_IMAGE) { Uri uri = null; if (null != intent && intent.getData() != null) { uri = intent.getData(); } else { String fileName = PreferencesUtils.getString(this, "tempName"); uri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName)); } if (uri != null) { cropImage(uri, CROP_PHOTO_CODE); } } else if (requestCode == CROP_PHOTO_CODE) { Uri photoUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT); if (isslinece) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), slience_image); zhizhao_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense"); } catch (URISyntaxException e) { e.printStackTrace(); } } else if (isZhengshu) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), zhengshu_iamge); xukezheng_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "LicenseKey"); } catch (URISyntaxException e) { e.printStackTrace(); } //upLoadImage(new File((new URI(photoUri.toString()))), "Photo"); } else if (isItem) { if (images.size() < 10) { shangpu_path.add(photoUri.toString()); try { upLoadImage(new File((new URI(photoUri.toString()))), "Seller"); } catch (URISyntaxException e) { e.printStackTrace(); } } else { Toast.makeText(FourStepRegisterActivity.this, "?9", Toast.LENGTH_SHORT).show(); } } //addImage(imagePath); } }
From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_PICTURE) { if (data != null) { Uri uri = data.getData(); // If the uri's null, we failed. Don't change anything. if (uri != null) { Cursor cursor;/* w w w. j a v a2 s.co m*/ cursor = getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.LATITUDE, MediaStore.Images.ImageColumns.LONGITUDE, MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null); cursor.moveToFirst(); mCurrentFile = cursor.getString(0); mPictureDate = cursor.getLong(3); // These two could very well be null or empty. Nothing // wrong with that. But if they're good, make a Location // out of them. String lat = cursor.getString(1); String lon = cursor.getString(2); try { double llat = Double.parseDouble(lat); double llon = Double.parseDouble(lon); mPictureLocation = new Location(""); mPictureLocation.setLatitude(llat); mPictureLocation.setLongitude(llon); } catch (Exception ex) { // If we get an exception, we got it because of the // number parser. Assume it's invalid. mPictureLocation = null; } cursor.close(); } } else { mPictureLocation = null; mPictureDate = -1; } // Always rebuild the thumbnail and reset submit, just in case. buildThumbnail(); setThumbnail(); resetSubmitButton(); updateCoords(); // We'll decode the bitmap at upload time so as not to keep a // potentially big chunky Bitmap around at all times. } }
From source file:com.chaturs.notepad.NoteEditor.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); final Intent intent = getIntent(); title = intent.getExtras().getString("note_title"); // Do some setup based on the action being performed. final String action = intent.getAction(); if (ACTION_EDIT.equals(action)) { // Requested to edit: set that state, and the data being edited. mState = STATE_EDIT;//w ww .j a va 2 s . c o m isSaved = false; mUri = intent.getData(); } else { // Whoops, unknown action! Bail. Log.e(TAG, "Unknown action, exiting"); finish(); return; } // Set the layout for this activity. You can find it in res/layout/note_editor.xml setContentView(R.layout.note_editor); preferences = getSharedPreferences(DOC_PREFERENCE, Context.MODE_PRIVATE); IpValue = preferences.getString(KEY_IPVALUE, ""); // The text view for our note, identified by its ID in the XML file. mText = (EditText) findViewById(R.id.note); // Get the note! mCursor = managedQuery(mUri, PROJECTION, null, null, null); // If an instance of this activity had previously stopped, we can // get the original text it started with. if (savedInstanceState != null) { mOriginalContent = savedInstanceState.getString(ORIGINAL_CONTENT); } DatabaseHandler databasehandler = DatabaseHandler.getInstance(); studyGroupList = databasehandler.listStudyGroupsInfo(); Iterator<StudyGroup> iterator = studyGroupList.iterator(); while (iterator.hasNext()) { StudyGroup studyGroup = iterator.next(); studyGroupNames.add(studyGroup.getName()); } }
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
private void photoSucess(Intent intent) { //URI????URI?URI?? //???try-catch??? Uri uri = intent.getData(); if (null == uri) { uri = mImageUri;/*ww w .jav a 2s .c o m*/ } ContentResolver resolver = getContext().getContentResolver(); XPathResolver pathResolver = new XPathResolver(null == uri ? null : uri.toString(), "", getContext()); Bitmap bitmap = null; try { if (!mAllowEdit) { String path = pathResolver.resolve(); if (!XStringUtils.isEmptyString(path)) { bitmap = XUtils.decodeBitmap(path); } } else { //??????Android??? bitmap = intent.getExtras().getParcelable("data"); //?????URI if (bitmap == null) { bitmap = getCroppedBitmap(intent); } } } catch (OutOfMemoryError e) { mCallbackCtx.error("OutOfMemoryError when decode image."); return; } if (mDestType == DATA_URL) { int rotate = 0; String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = resolver.query(uri, cols, null, null, null); if (null != cursor) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (0 != rotate) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } bitmap = scaleBitmap(bitmap); processPicture(bitmap); bitmap.recycle(); bitmap = null; System.gc(); } else if (mTargetHeight > 0 && mTargetWidth > 0) { try { Bitmap scaleBitmap = scaleBitmap(bitmap); String fileName = XConfiguration.getInstance().getWorkDirectory() + RESIZED_PIC_NAME; OutputStream os = new FileOutputStream(fileName); scaleBitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os); os.close(); bitmap.recycle(); bitmap = null; scaleBitmap.recycle(); scaleBitmap = null; mCallbackCtx.success("file://" + fileName + "?" + System.currentTimeMillis()); System.gc(); } catch (Exception e) { mCallbackCtx.error("Error retrieving image."); return; } } else { mCallbackCtx.success(XConstant.FILE_SCHEME + pathResolver.resolve()); } }
From source file:com.cloverstudio.spika.CameraCropActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { switch (requestCode) { case GALLERY: try { Uri selected_image = data.getData(); String selected_image_path = getImagePath(selected_image); onPhotoTaken(selected_image_path); } catch (Exception e) { Toast.makeText(this, "Error loading image from Gallery!", Toast.LENGTH_LONG).show(); e.printStackTrace();/*from w w w . j a v a 2 s . co m*/ finish(); } break; case CAMERA: File file = new File(_path); boolean exists = file.exists(); if (exists) onPhotoTaken(_path); else Toast.makeText(getBaseContext(), "Something goes wrong while taking picture, please try again.", Toast.LENGTH_SHORT).show(); break; default: finish(); break; } } /** if there is no image, just finish the activity */ else { finish(); } }
From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java
@OnActivityResult(ACTION_SAVE_DOCUMENT) void onDocumentSaved(int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = data.getData(); copyFile(exportFile, uri);// w w w . j a v a2s. c o m } else { onExportAuditDocxFinished(); } }