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:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == TAKE_PHOTO_CODE) {

            photoBitmap = BitmapFactory.decodeFile(photoUri.getPath());
            Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300);
            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            //********** Update parse with image

            // Convert bitmap to a byte array
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] image = stream.toByteArray();

            // Create the ParseFile with an image
            final ParseFile file = new ParseFile(
                    "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image);

            //posting an image file with campaign id to Parse to Images object
            ParseObject photoPost = new ParseObject("Images");
            photoPost.put("imagePost", file);
            photoPost.put("campaignId", campaign.getObjectId());
            photoPost.saveInBackground(new SaveCallback() {
                @Override/*from  www. j  a v a  2s . com*/
                public void done(ParseException e) {
                    getImagesUploadedByUserForCampaign(campaign.getObjectId());
                }
            });

        } else if (requestCode == PICK_PHOTO_CODE) {

            photoUri = data.getData();
            try {
                photoBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
            } catch (IOException e) {
                e.printStackTrace();
            }

            Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300);
            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            //********** Update parse with image
            //ivCampaignImage.setImageBitmap(resizedImage);

            // Convert bitmap to a byte array
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] image = stream.toByteArray();

            // Create the ParseFile with an image
            final ParseFile file = new ParseFile(
                    "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image);

            //posting an image file with campaign id to Parse to Images object
            ParseObject photoPost = new ParseObject("Images");
            photoPost.put("imagePost", file);
            photoPost.put("campaignId", campaign.getObjectId());
            photoPost.saveInBackground();
            photoPost.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    getImagesUploadedByUserForCampaign(campaign.getObjectId());
                }
            });

        } else if (requestCode == CROP_PHOTO_CODE) {
            photoBitmap = data.getParcelableExtra("data");

            ivCampaignImage.getAdjustViewBounds();
            ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY);
            ivCampaignImage.setImageBitmap(photoBitmap);
            Toast.makeText(this, "I just took a picture", Toast.LENGTH_LONG).show();

        }
    }
}

From source file:com.chaqianma.jd.fragment.PersonalAssetsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case REQUEST_SDK_IMGS:
            if (data != null && data.getData() != null) {
                Uri imgUri = data.getData();
                ContentResolver resolver = getActivity().getContentResolver();
                String[] pojo = { MediaStore.Images.Media.DATA };
                Cursor cursor = null;
                try {
                    cursor = resolver.query(imgUri, pojo, null, null, null);
                    if (cursor != null && cursor.getCount() > 0) {
                        int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                        cursor.moveToFirst();
                        new Thread(new BaseFragment.ImgRunable(cursor.getString(colunm_index), fileType,
                                selIdxTag, new UpdateUIHandler())).start();
                        //mHandler.post(new ImgRunable(cursor.getString(colunm_index)));
                    } else {
                        JDToast.showLongText(getActivity(), "");
                    }/*from   w  w  w .j a  v  a  2s.c o m*/
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                }
            }
            break;
        case REQUEST_TAKE_PHOTO:
            // mHandler.post(mRunnable);
            new Thread(
                    new BaseFragment.ImgRunable(Constants.TEMPPATH, fileType, selIdxTag, new UpdateUIHandler()))
                            .start();
            break;
        default:
            break;
        }
    }
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Imports a CA certificate from the given data URI.
 *
 * @param intent Intent that contains the CA data URI.
 *///  ww w.  ja  v  a2  s .co  m
private void importCaCertificateFromIntent(Intent intent) {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }
    Uri data = null;
    if (intent != null && (data = intent.getData()) != null) {
        boolean isCaInstalled = false;
        try {
            InputStream certificateInputStream = getActivity().getContentResolver().openInputStream(data);
            if (certificateInputStream != null) {
                ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
                byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                int len = 0;
                while ((len = certificateInputStream.read(buffer)) > 0) {
                    byteBuffer.write(buffer, 0, len);
                }
                isCaInstalled = mDevicePolicyManager.installCaCert(mAdminComponentName,
                        byteBuffer.toByteArray());
            }
        } catch (IOException e) {
            Log.e(TAG, "importCaCertificateFromIntent: ", e);
        }
        showToast(isCaInstalled ? R.string.install_ca_successfully : R.string.install_ca_fail);
    }
}

From source file:com.nnm.smsviet.Message.java

/**
 * Get a {@link OnLongClickListener} to save the attachment.
 * //from  w ww  . jav  a 2s  . c  o  m
 * @param context
 *            {@link Context}
 * @return {@link OnLongClickListener}
 */
public OnLongClickListener getSaveAttachmentListener(final Context context) {
    if (this.contentIntent == null) {
        return null;
    }

    return new OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            try {
                Log.d(TAG, "save attachment: " + Message.this.id);
                String fn = ATTACHMENT_FILE;
                final Intent ci = Message.this.contentIntent;
                final String ct = ci.getType();
                Log.d(TAG, "content type: " + ct);
                if (ct.startsWith("image/")) {
                    if (ct.equals("image/jpeg")) {
                        fn += "jpg";
                    } else if (ct.equals("image/gif")) {
                        fn += "gif";
                    } else {
                        fn += "png";
                    }
                } else if (ct.startsWith("audio/")) {
                    if (ct.equals("audio/3gpp")) {
                        fn += "3gpp";
                    } else if (ct.equals("audio/mpeg")) {
                        fn += "mp3";
                    } else if (ct.equals("audio/mid")) {
                        fn += "mid";
                    } else {
                        fn += "wav";
                    }
                } else if (ct.startsWith("video/")) {
                    if (ct.equals("video/3gpp")) {
                        fn += "3gpp";
                    } else {
                        fn += "avi";
                    }
                } else {
                    fn += "ukn";
                }
                final File file = Message.this.createUniqueFile(Environment.getExternalStorageDirectory(), fn);
                InputStream in = context.getContentResolver().openInputStream(ci.getData());
                OutputStream out = new FileOutputStream(file);
                IOUtils.copy(in, out);
                out.flush();
                out.close();
                in.close();
                Log.i(TAG, "attachment saved: " + file.getPath());
                Toast.makeText(context, context.getString(R.string.attachment_saved) + " " + fn,
                        Toast.LENGTH_LONG).show();
                return true;
            } catch (IOException e) {
                Log.e(TAG, "IO ERROR", e);
                Toast.makeText(context, R.string.attachment_not_saved, Toast.LENGTH_LONG).show();
            }
            return true;
        }
    };
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Imports a certificate to the managed profile. If the provided decryption password is
 * incorrect, shows a try again prompt. Otherwise, shows a prompt for the certificate alias.
 *
 * @param intent Intent that contains the certificate data uri.
 * @param password The password to decrypt the certificate.
 * @param attempts The number of times user entered incorrect password.
 *//* w  w w.  ja va2 s .c om*/
private void importKeyCertificateFromIntent(Intent intent, String password, int attempts) {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }
    Uri data = null;
    if (intent != null && (data = intent.getData()) != null) {
        // If the password is null, try to decrypt the certificate with an empty password.
        if (password == null) {
            password = "";
        }
        try {
            CertificateUtil.PKCS12ParseInfo parseInfo = CertificateUtil
                    .parsePKCS12Certificate(getActivity().getContentResolver(), data, password);
            showPromptForKeyCertificateAlias(parseInfo.privateKey, parseInfo.certificate, parseInfo.alias);
        } catch (KeyStoreException | FileNotFoundException | CertificateException | UnrecoverableKeyException
                | NoSuchAlgorithmException e) {
            Log.e(TAG, "Unable to load key", e);
        } catch (IOException e) {
            showPromptForCertificatePassword(intent, ++attempts);
        } catch (ClassCastException e) {
            showToast(R.string.not_a_key_certificate);
        }
    }
}

From source file:com.bwash.bwashcar.activities.CompanyActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case CAMERA_REQUEST_CODE: // ?
            //  File temp = new File(mTempPhotoPath);
            // //from  w ww .j a  v  a2s.  co  m
            //   startCropActivity(sourceUri);
            onUploadQiniu();

            switch (switchType.getType()) {
            case "license":
                //
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), sourceUri.toString(),
                        iv_license_image, R.drawable.ic_image_holder);
                break;
            case "idfront":
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), sourceUri.toString(),
                        iv_owner_id_front, R.drawable.ic_image_holder);

                break;
            case "idback":
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), sourceUri.toString(),
                        iv_owner_id_back, R.drawable.ic_image_holder);

                break;
            }
            break;
        case GALLERY_REQUEST_CODE: // ?
            // 
            //    startCropActivity(data.getData());
            try {
                Uri uri = data.getData();
                filePath = ImageUtils.getRealFilePathFromImageUri(this, uri);
                //    inFile = new File(new URI(uri.toString()));
            } catch (Exception e) {

            }
            onUploadQiniu();
            switch (switchType.getType()) {
            case "license":
                //
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), filePath,
                        iv_license_image, R.drawable.ic_image_holder);
                break;
            case "idfront":
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), filePath,
                        iv_owner_id_front, R.drawable.ic_image_holder);

                break;
            case "idback":
                ImageLoaderProxy.getInstance().displayImage(this.getApplicationContext(), filePath,
                        iv_owner_id_back, R.drawable.ic_image_holder);

                break;
            }

            break;
        case UCrop.REQUEST_CROP: // ?
            handleCropResult(data);
            break;
        case UCrop.RESULT_ERROR: // ?
            handleCropError(data);
            break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:cgeo.geocaching.CacheListActivity.java

private boolean isInvokedFromAttachment() {
    final Intent intent = getIntent();
    return Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null;
}

From source file:com.ola.insta.BookingAcivity.java

/**
 * Receiving speech input/*from w  w w. j av a  2 s .  co m*/
 * */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && null != data) {
        switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT:

            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            boolean isMatched = false;
            for (String string : result) {
                if (string.contains(Constants.VOICE_MESSAGE)) {
                    /*
                     * Toast.makeText( getApplicationContext(),
                     * getApplicationContext().getString(
                     * R.string.cab_booked), Toast.LENGTH_SHORT).show();
                     */

                    // Call REST API

                    if (Utilities.isNetworkAvailable(this)) {
                        new GetCabBookingRequestTask().execute();
                    } else {
                        Utilities mUltilities = new Utilities();
                        mUltilities.showDialogConfirm(BookingAcivity.this, "Message",
                                "Please check network connection", true).show();
                    }
                    isMatched = true;
                    break;
                }

            }
            if (!isMatched) {
                speakOut("Please try again!");
                Toast.makeText(getApplicationContext(),
                        getApplicationContext().getString(R.string.speech_try_again), Toast.LENGTH_SHORT)
                        .show();
            }

            break;

        case REQ_CODE_SELECT_CONTACT:
            Uri uri = data.getData();
            String id = uri.getLastPathSegment();

            Cursor contact = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?",
                    new String[] { id }, null);
            if (contact.moveToFirst()) {
                if (contact.getString(contact.getColumnIndex(Phone.HAS_PHONE_NUMBER)) != null) {

                    final String contactName = contact.getString(contact.getColumnIndex(Phone.DISPLAY_NAME));
                    final String phoneNum = contact.getString(contact.getColumnIndex(Phone.NUMBER));

                    MaterialDialog dialog = new MaterialDialog(context,
                            context.getString(R.string.emergency_contact),
                            "Name : " + contactName + "\nNumber : " + phoneNum, context.getString(R.string.add),
                            context.getString(R.string.cancel));
                    dialog.setOnAcceptButtonClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            saveToShrPref(contactName, phoneNum);
                            Toast.makeText(context, "Emergency contact saved successfully!", Toast.LENGTH_LONG)
                                    .show();

                        }
                    });
                    dialog.setOnCancelButtonClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    });
                    dialog.show();

                } else
                    Toast.makeText(context, context.getString(R.string.contact_dont_have_number),
                            Toast.LENGTH_LONG).show();
            }
            break;

        default:
            break;
        }

    }
}

From source file:com.hackensack.umc.activity.ProfileSelfieActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (selectedImageView == Constant.INSU_PROOF_FRONT || selectedImageView == Constant.INSU_PROOF_BACK
            || selectedImageView == Constant.ID_PROOF_FRONT || selectedImageView == Constant.ID_PROOF_BACK) {
        Fragment fragment = (Fragment) getSupportFragmentManager().findFragmentByTag("IsuranceFragment");
        if (fragment != null) {
            fragment.onActivityResult(requestCode, resultCode, data);
            return;
        }/*from  ww w. j a va 2s  .c om*/
    }
    switch (requestCode) {
    case Constant.FRAGMENT_CONST_REQUEST_IMAGE_CAPTURE:
        if (resultCode == RESULT_OK) {
            /*Intent intent = new Intent(ProfileSelfieActivity.this, ActivityCropImage.class);
            intent.setData(imageUri);
            startActivityForResult(intent, Constant.CROP_IMAGE_ACTIVITY);*/

            cropPictureIntent(imageUri);
        }
        break;
    default:
        Uri imageUriFromIntent = null;
        if (resultCode == RESULT_OK) {
            try {
                if (data != null) {
                    if (selectedImageView == Constant.SELFIE) {
                        imageUriFromIntent = data.getData();
                        if (imageUriFromIntent == null) {
                            imageUriFromIntent = data.getExtras().getParcelable("data");
                        }

                        if (imageUriFromIntent == null) {
                            imageUriFromIntent = imageUri;
                        }
                        /*CameraFunctionality.setPhotoToImageView(imageUri.toString(), imgSelfie, ProfileSelfieActivity.this);
                        byte[] byteArray = getIntent().getByteArrayExtra(Constant.BITMAP_IMAGE);
                        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
                        getImageUris(imageUri, 5,bmp,null);*/

                        /*   Bitmap bitmapImage = CameraFunctionality.unCompressedImage(data.getByteArrayExtra(Constant.BITMAP_IMAGE));
                                
                           pathSelfie=Base64Converter.createBase64StringFroImage(bitmapImage,ProfileSelfieActivity.this);*/

                        txtSefileSet.setText(R.string.done);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                imageUriFromIntent = imageUri;

            }
            try {
                Bitmap bitmapImage;
                bitmapImage = CameraFunctionality.getBitmapFromFile(imageUriFromIntent.toString(),
                        ProfileSelfieActivity.this);
                bitmapImage = CameraFunctionality.rotateBitmap(bitmapImage, imageUri.toString());

                String base64 = Base64Converter.createBase64StringFromBitmap(bitmapImage,
                        ProfileSelfieActivity.this);
                getImageUris(imageUriFromIntent, selectedImageView, null, base64);

                CameraFunctionality.setBitMapToImageView(imageUriFromIntent.toString(), bitmapImage, imgSelfie,
                        ProfileSelfieActivity.this);

                //   deleteLastFromDCIM();
                // CameraFunctionality.deleteImageAfterUploading(imageUriFromIntent.toString(),ProfileSelfieActivity.this);
                /*    ImageLoader imageLoader=new ImageLoader(ProfileSelfieActivity.this);
                imageLoader.displayImage(imageUriFromIntent.toString(),imgSelfie);*/
                //pathSelfie = imageUri;

            } catch (NullPointerException e) {

            }

        }
        break;
    }
}

From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java

/** Called with an Activity we started with an Intent returns. */
@Override/*  w  w w  . j a  va 2  s. co m*/
protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) {
    if (requestCode == REQUEST_CODE_CHOOSE_CONTACT) {
        // The user finished saving their ringtone and they're
        // just applying it to a contact.  When they return here,
        // they're done.
        finish();
        return;
    }

    if (requestCode != REQUEST_CODE_RECORD) {
        return;
    }

    if (resultCode != RESULT_OK) {
        finish();
        return;
    }

    if (dataIntent == null) {
        finish();
        return;
    }

    // Get the recorded file and open it, but save the uri and
    // filename so that we can delete them when we exit; the
    // recorded file is only temporary and only the edited & saved
    // ringtone / other sound will stick around.
    mRecordingUri = dataIntent.getData();
    mRecordingFilename = getFilenameFromUri(mRecordingUri);
    mFilename = mRecordingFilename;
    loadFromFile();
}