Example usage for android.content Intent getData

List of usage examples for android.content Intent getData

Introduction

In this page you can find the example usage for android.content Intent getData.

Prototype

public @Nullable Uri getData() 

Source Link

Document

Retrieve data this intent is operating on.

Usage

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (intent == null || intent.getData() == null || !intent.getData().toString().startsWith(mCallbackURL)) {
        return;/*from   ww w .  j ava2  s . c  om*/
    }

    String verifier = intent.getData().getQueryParameter("oauth_verifier");

    AsyncTask<String, Void, AccessToken> task = new AsyncTask<String, Void, AccessToken>() {
        @Override
        protected AccessToken doInBackground(String... params) {
            try {
                return mTwitter.getOAuthAccessToken(mRequestToken, params[0]);
            } catch (TwitterException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(AccessToken accessToken) {
            if (accessToken != null) {
                Toast.makeText(getApplicationContext(),
                        getApplicationContext().getString(R.string.twitter_auth_succeed), Toast.LENGTH_LONG)
                        .show();
                TwitterUtility.storeAccessToken(getApplicationContext(), accessToken);
            } else {
                Toast.makeText(getApplicationContext(),
                        getApplicationContext().getString(R.string.twitter_auth_fail), Toast.LENGTH_LONG)
                        .show();
            }
        }
    };
    task.execute(verifier);
}

From source file:com.krayzk9s.imgurholo.services.UploadService.java

@Override
protected void onHandleIntent(Intent intent) {
    ids = new ArrayList<String>();
    if (intent.hasExtra("images")) {
        Log.d("recieving", "handling multiple");
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra("images");
        totalUpload = list.size();//www . j av a 2s. c o m
        for (Parcelable parcel : list) {
            Uri uri = (Uri) parcel;
            Log.d("recieving", uri.toString());
            SendImage sendImage = new SendImage(apiCall, FileUtils.getPath(this, uri), getApplicationContext(),
                    getResources(), this);
            Log.d("recieving", "executing");
            sendImage.execute();
        }
    } else {
        totalUpload = -1;
        SendImage sendImage = new SendImage(apiCall,
                FileUtils.getPath(getApplicationContext(), intent.getData()), getApplicationContext(),
                getResources(), this);
        sendImage.execute();
    }
}

From source file:com.foregroundcameraplugin.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits./*from   w  w w .  j av  a2  s .  c om*/
 * 
 * @param requestCode
 *            The request code originally supplied to
 *            startActivityForResult(), allowing you to identify who this
 *            result came from.
 * @param resultCode
 *            The integer result code returned by the child activity through
 *            its setResult().
 * @param intent
 *            An Intent, which can return result data to the caller (various
 *            data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // If image available
    if (resultCode == Activity.RESULT_OK) {
        try {
            // Create an ExifHelper to save the exif data that is lost
            // during compression
            ExifHelper exif = new ExifHelper();
            exif.createInFile(
                    getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg");
            exif.readExifData();

            // Read in bitmap of captured image
            Bitmap bitmap;
            try {
                bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
            } catch (FileNotFoundException e) {
                Uri uri = intent.getData();
                android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
                bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
            }

            bitmap = scaleBitmap(bitmap);

            // Create entry in media store for image
            // (Don't use insertImage() because it uses default compression
            // setting of 50 - no way to change it)
            ContentValues values = new ContentValues();
            values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = null;
            try {
                uri = this.cordova.getActivity().getContentResolver()
                        .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (UnsupportedOperationException e) {
                LOG.d(LOG_TAG, "Can't write to external media storage.");
                try {
                    uri = this.cordova.getActivity().getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException ex) {
                    LOG.d(LOG_TAG, "Can't write to internal media storage.");
                    this.failPicture("Error capturing image - no media storage found.");
                    return;
                }
            }

            // Add compressed version of captured image to returned media
            // store Uri
            OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
            os.close();

            // Restore exif data to file
            exif.createOutFile(getRealPathFromURI(uri, this.cordova));
            exif.writeExifData();

            // Send Uri back to JavaScript for viewing image
            this.callbackContext.success(getRealPathFromURI(uri, this.cordova));

            bitmap.recycle();
            bitmap = null;
            System.gc();

            checkForDuplicateImage();
        } catch (IOException e) {
            e.printStackTrace();
            this.failPicture("Error capturing image.");
        }
    }

    // If cancelled
    else if (resultCode == Activity.RESULT_CANCELED) {
        this.failPicture("Camera cancelled.");
    }

    // If something else
    else {
        this.failPicture("Did not complete!");
    }
}

From source file:com.ximai.savingsmore.save.activity.AddGoodsAcitivyt.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode != RESULT_OK) {
        return;/*w ww .  j a va 2 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);
        try {
            upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        //addImage(imagePath);

    }
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final BaseApplication application = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = application.getOneDriveClient();

    if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD && data != null && data.getData() != null
            && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) {

        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setTitle(R.string.upload_in_progress_title);
        dialog.setMessage(getString(R.string.upload_in_progress_message));
        dialog.setIndeterminate(false);/*from  w w  w . ja v a  2  s.  c  o  m*/
        dialog.setCancelable(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format));
        dialog.show();
        final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                try {
                    final ContentResolver contentResolver = getActivity().getContentResolver();
                    final ContentProviderClient contentProvider = contentResolver
                            .acquireContentProviderClient(data.getData());
                    final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData());
                    contentProvider.release();

                    // Fix up the file name (needed for camera roll photos, etc)
                    final String filename = FileContent.getValidFileName(contentResolver, data.getData());
                    final Option option = new QueryOption("@name.conflictBehavior", "fail");
                    oneDriveClient.getDrive().getItems(mItemId).getChildren().byId(filename).getContent()
                            .buildRequest(Collections.singletonList(option))
                            .put(fileInMemory, new IProgressCallback<Item>() {
                                @Override
                                public void success(final Item item) {
                                    dialog.dismiss();
                                    Toast.makeText(getActivity(),
                                            application.getString(R.string.upload_complete, item.name),
                                            Toast.LENGTH_LONG).show();
                                    refresh();
                                }

                                @Override
                                public void failure(final ClientException error) {
                                    dialog.dismiss();
                                    if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {
                                        Toast.makeText(getActivity(), R.string.upload_failed_name_conflict,
                                                Toast.LENGTH_LONG).show();
                                    } else {
                                        Toast.makeText(getActivity(),
                                                application.getString(R.string.upload_failed, filename),
                                                Toast.LENGTH_LONG).show();
                                    }
                                }

                                @Override
                                public void progress(final long current, final long max) {
                                    dialog.setProgress((int) current);
                                    dialog.setMax((int) max);
                                }
                            });
                } catch (final Exception e) {
                    Log.e(getClass().getSimpleName(), e.getMessage());
                    Log.e(getClass().getSimpleName(), e.toString());
                }
                return null;
            }
        };
        uploadFile.execute();
    }
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.e("Activity sss1", "sds");
    if (requestCode == GALLERY_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                uri = data.getData();
                image_path = uri.getPath();
                //addNewVehicalFragment.setImagePath(image_path);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                try {
                    // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
                    options.inSampleSize = calculateInSampleSize(options, 100, 100);
                    options.inJustDecodeBounds = false;
                    Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null,
                            options);//from  w w  w  .  j  av a2  s  . com

                    //   car_image.setImageBitmap(image);
                    //car_image1.setImageBitmap(image);

                    /* Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
                     ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                     File destination = new File(getCacheDir(), "car.jpg");
                     FileOutputStream fo;
                     try {
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                     } catch (IOException e) {
                    e.printStackTrace();
                     }
                     image_path = destination.getAbsolutePath();*/
                    // car_image.setImageBitmap(bitmap);
                    //  addNewVehicalFragment.setImagePath(image_path);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    } else if (requestCode == CAMERA_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data.hasExtra("data")) {
                Bitmap bitmap = (Bitmap) data.getExtras().get("data");
                /* ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                 bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                 File destination = new File(getCacheDir(), "car.jpg");
                 FileOutputStream fo;
                 try {
                fo = new FileOutputStream(destination);
                fo.write(bytes.toByteArray());
                fo.close();
                 } catch (IOException e) {
                e.printStackTrace();
                 }
                 image_path = destination.getAbsolutePath();*/
                //  car_image.setImageBitmap(bitmap);
                //  car_image1.setImageBitmap(bitmap);
                // addNewVehicalFragment.setImagePath(image_path);
            } else if (data.getExtras() == null) {

                Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

                BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath());
                //img_view_drivingLicense.setImageDrawable(thumbnail);
                //    car_image.setImageDrawable(thumbnail);
                //  car_image1.setImageDrawable(thumbnail);

            }

        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits./*from  w  ww .  j a  va2  s  . c o m*/
 * 
 * @param requestCode
 *            The request code originally supplied to
 *            startActivityForResult(), allowing you to identify who this
 *            result came from.
 * @param resultCode
 *            The integer result code returned by the child activity through
 *            its setResult().
 * @param intent
 *            An Intent, which can return result data to the caller (various
 *            data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // If image available
    if (resultCode == Activity.RESULT_OK) {
        try {
            // Create an ExifHelper to save the exif data that is lost
            // during compression
            ExifHelper exif = new ExifHelper();
            exif.createInFile(
                    getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg");
            exif.readExifData();

            // Read in bitmap of captured image
            Bitmap bitmap;
            try {
                bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
            } catch (FileNotFoundException e) {
                Uri uri = intent.getData();
                android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
                bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
            }

            bitmap = scaleBitmap(bitmap);

            // Create entry in media store for image
            // (Don't use insertImage() because it uses default compression
            // setting of 50 - no way to change it)
            ContentValues values = new ContentValues();
            values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = null;
            try {
                uri = this.cordova.getActivity().getContentResolver()
                        .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (UnsupportedOperationException e) {
                LOG.d(LOG_TAG, "Can't write to external media storage.");
                try {
                    uri = this.cordova.getActivity().getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException ex) {
                    LOG.d(LOG_TAG, "Can't write to internal media storage.");
                    this.failPicture("Error capturing image - no media storage found.");
                    return;
                }
            }

            // Add compressed version of captured image to returned media
            // store Uri
            OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
            os.close();

            // Restore exif data to file
            exif.createOutFile(getRealPathFromURI(uri, this.cordova));
            exif.writeExifData();

            // Send Uri back to JavaScript for viewing image
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri.toString()));
            //                  getRealPathFromURI(uri, this.cordova))); WRONG. Needs URI

            bitmap.recycle();
            bitmap = null;
            System.gc();

            checkForDuplicateImage();
        } catch (IOException e) {
            e.printStackTrace();
            this.failPicture("Error capturing image.");
        }
    }

    // If cancelled
    else if (resultCode == Activity.RESULT_CANCELED) {
        this.failPicture("Camera cancelled.");
    }

    // If something else
    else {
        this.failPicture("Did not complete!");
    }
}

From source file:edu.cens.loci.ui.VisitDetailActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    MyLog.d(LociConfig.D.UI.DEBUG, TAG,/*  w w w . jav a  2 s . c om*/
            "onActivityResult:" + String.format(" requestCode=%d resultCode=%d ", requestCode, resultCode));
    if (data != null)
        MyLog.d(LociConfig.D.UI.DEBUG, TAG, "onActivityResult:" + data.toString());

    switch (requestCode) {
    case SUBACTIVITY_ADD_PLACE:
        if (resultCode == RESULT_OK) {
            // created or add to existing place successfully. update visits' placeid.
            final long placeId = ContentUris.parseId(data.getData());
            final long visitId = ContentUris.parseId(getIntent().getData());
            MyLog.d(LociConfig.D.UI.DEBUG, TAG, "[Update] placeId=" + placeId + ", visitId=" + visitId);
            mDbUtils.updateVisitPlaceId(visitId, placeId);
        }
        break;
    case SUBACTIVITY_CHANGE_PLACE:
        if (resultCode == RESULT_OK) {
            // created or add to existing place successfully. update visits' placeid
            //MyLog.d(LociConfig.D.UI.DEBUG, TAG, "[VisitDetail] data:" + data.getData().toString());
            final long placeId = ContentUris.parseId(data.getData());
            final long visitId = ContentUris.parseId(getIntent().getData());
            MyLog.d(LociConfig.D.UI.DEBUG, TAG, "[Update] placeId=" + placeId + ", visitId=" + visitId);
            mDbUtils.updateVisitPlaceId(visitId, placeId);
        }
    }
}

From source file:com.abc.driver.PersonalActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT
            || requestCode == CellSiteConstants.PICK_USER_PORTRAIT) {
        Uri uri = null;/*  w w  w  .  j av  a  2 s  .  co m*/
        if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_USER_PORTRAIT) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            imageUri = Uri.fromFile(new File(filePath));
        } else // This is a bug, in some cases, some images like
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setProfileImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        doCrop();
        Log.d(TAG, "onActivityResult PICK_PICTURE");

    } else if (requestCode == CellSiteConstants.CROP_PICTURE) {
        Log.d(TAG, "crop picture");
        // processFile();

        if (data != null) {
            Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            app.setPortaritBitmap(photo);
            mUserPortraitIv.setImageBitmap(photo);
            mUpdateImageTask = new UpdateImageTask();
            mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(photo),
                    CellSiteConstants.UPDATE_USER_PORTRAIT_URL);

            isPortraitChanged = true;
        }
    } else if (requestCode == CellSiteConstants.TAKE_IDENTITY
            || requestCode == CellSiteConstants.PICK_IDENTITY) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_IDENTITY) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_IDENTITY) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setIdentityImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH,
                CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false);

        mUserIdentityIv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp),
                CellSiteConstants.UPDATE_USER_IDENTITY_URL);

    } else if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE
            || requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setDriverLicenseImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH,
                CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false);

        mUserDriverLicenseIv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp),
                CellSiteConstants.UPDATE_DRIVER_LICENSE_URL);

    }
}

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
        if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
            Bitmap bm = (Bitmap) data.getExtras().get("data");
            showPopupMenuAskingImageSize(null, bm);
        } else if (data != null && data.getData() != null) {
            String filePath = getRealPathFromURI(data.getData());
            showPopupMenuAskingImageSize(filePath, null);
        } else if (imageToUploadUri != null) {
            String filePath = imageToUploadUri.getPath();
            showPopupMenuAskingImageSize(filePath, null);
        } else {// w  w  w.j  av  a2 s .  co m
            File file = new File(Environment.getExternalStorageDirectory(),
                    getString(R.string.temp_photo_name));
            if (file.exists()) {
                imageToUploadUri = Uri.fromFile(file);
                String filePath = imageToUploadUri.getPath();
                showPopupMenuAskingImageSize(filePath, null);
            }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}