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.zhihuigu.sosoOffice.RegisterThirdActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) { //  RESULT_OK 
        Log.e(TAG, "ActivityResult resultCode error");
        return;/*from   w  w w  .j a v a 2s .c om*/
    }
    Bitmap bm = null;
    // ContentProvider ContentResolver
    ContentResolver resolver = getContentResolver();
    // Activity
    if (requestCode == IMAGE_CODE) {//
        String imgPath = "";
        Uri originalUri = data.getData(); // uri
        //            bm = MediaStore.Images.Media.getBitmap(resolver, originalUri); // bitmap
        // 
        String[] proj = { MediaStore.Images.Media.DATA };
        // androidAndroid
        Cursor cursor = managedQuery(originalUri, proj, null, null, null);
        //            InputStream inputStream = resolver.openInputStream(originalUri);

        //  
        if (cursor == null) {
            imgPath = data.getDataString();
        } else {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            //  
            cursor.moveToFirst();
            // www.2cto.com
            imgPath = cursor.getString(column_index);
        }
        File fromFile = new File(imgPath);
        // 
        if (fromFile != null && fromFile.exists()) {
            fileName = CommonUtils.getFileName();// 
            File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD);
            if (!file.exists()) {
                file.mkdirs();
            }
            sdcardTempFile = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName);
            //               path = sdcardTempFile.getAbsolutePath();
            //               FileCopyUtil.copyfile(fromFile, sdcardTempFile, true);

            Bitmap bitmap = CommonUtils.getDrawable(fromFile.getAbsolutePath(),
                    MyApplication.getInstance(this).getScreenWidth(),
                    MyApplication.getInstance(this).getScreenHeight());
            if (bitmap != null) {
                bitmap = CommonUtils.RotateImg(fromFile.getAbsolutePath(), bitmap);//90
                boolean copy = CommonUtils.OutPutImage(sdcardTempFile, bitmap);
                if (copy) {
                    /*File oldFile = new File(path);
                    oldFile.delete();*/
                    path = sdcardTempFile.getAbsolutePath();
                }
            } else {
                Toast.makeText(this, "", 3000).show();
            }
        }
        bm = CommonUtils.getDrawable(path, photoView);
        if (bm != null) {
            photo_tag = true;
            bottomLinear.setVisibility(View.GONE);
            photoView.setImageBitmap(bm);
        } else {
            Toast.makeText(this, "", 3000).show();
        }

    } else if (requestCode == REQUEST_CODE_TAKE_PICTURE) {//   
        fileName = CommonUtils.getFileName();// 
        File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD);
        if (!file.exists()) {
            file.mkdirs();
        }
        sdcardTempFile = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName);
        if (CommonUtils.isHasSdcard()) {//   
            path = SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD + MyApplication.getInstance(this).getFileName();
            Bitmap bitmap = CommonUtils.getDrawable(path, 500, 500);
            bitmap = CommonUtils.RotateImg(path, bitmap);//90
            boolean copy = CommonUtils.OutPutImage(sdcardTempFile, bitmap);
            if (copy) {
                File oldFile = new File(path);
                oldFile.delete();
                path = sdcardTempFile.getAbsolutePath();
            }

            bm = CommonUtils.getDrawable(path, photoView);
            photo_tag = true;
            bottomLinear.setVisibility(View.GONE);
            photoView.setImageBitmap(bm);
        } else { //    
            Bundle extras = data.getExtras();
            bm = (Bitmap) extras.get("data");
            photo_tag = true;
            bottomLinear.setVisibility(View.GONE);
            photoView.setImageBitmap(bm);
        }
    }
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

/** Called when the activity is first created. */
@Override/*from ww w.jav  a2s.  co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    resetContent();

    final Intent i = this.getIntent();
    // Decide if application is called from launcher or from other application
    // by using action. If you use category it can be null, that is the case
    // with gmail application and link from that application.
    if (Intent.ACTION_VIEW.equals(i.getAction())) {
        // Link to comic
        boolean tryArchive = true;
        if (comicDef.isComicUrl(i.getData())) {
            try {
                loadComic(provider.comicDataUrlForUrl(i.getData()));
                tryArchive = false;
            } catch (NumberFormatException e) {
                // Fall through to trying the URL as an archive URL
            }
        }
        if (tryArchive) {
            if (comicDef.isArchiveUrl(i.getData())) {
                showArchive();
                this.finish();
            } else {
                // it wasn't a link to comic or to the archive
                // last ditch attempt: was it a link to the home page?
                if (comicDef.isHomeUrl(i.getData())) {
                    goToFinal();
                } else {
                    toast("This comic viewer can't display this content.");
                    this.finish();
                }
            }
        }
    } else {
        // Started by application icon
        if (isReopenLastComic()) {
            try {
                loadComic(createComicUri(getLastReadComic()));
            } catch (NumberFormatException e) {
                goToFinal();
            }
        } else {
            goToFinal();
        }
    }
}

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

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case Constant.FRAGMENT_CONST_REQUEST_IMAGE_CAPTURE:
        if (resultCode == RESULT_OK) {
            Intent intent = new Intent(ProfileSelfieActivityCustomeCam.this, ActivityCropImage.class);
            intent.setData(imageUri);/*from  w w  w  .  ja  v a2 s.c  o m*/
            startActivityForResult(intent, Constant.CROP_IMAGE_ACTIVITY);
        }
        break;
    case Constant.CROP_IMAGE_ACTIVITY:
        if (resultCode == RESULT_OK) {
            try {
                if (data != null) {
                    imageUri = data.getData();
                    CameraFunctionality.setPhotoToImageView(imageUri.toString(), imgSelfie,
                            ProfileSelfieActivityCustomeCam.this);
                    getImageUris(imageUri, 5);
                    txtSefileSet.setText(R.string.done);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        break;
    }
}

From source file:com.khoahuy.phototag.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    setIntent(data);/*from w ww .  j ava2  s .  c  o  m*/
    switch (requestCode) {
    case ACTION_TAKE_PHOTO_B: {
        if (resultCode == RESULT_OK) {
            // Check nfcid. If it existed, checkout it
            if (existedUID(nfcid)) {
                checkoutNFCItem(nfcid);
            }
            handleBigCameraPhoto();
        } else if (resultCode == RESULT_CANCELED) {
            // Goto view image of nfcid
            if (existedUID(nfcid))
                displayNFCItem(nfcid);
        }
        break;
    }
    case ACTION_TAKE_PHOTO_M: {
        if (resultCode == RESULT_OK) {
            handleSmallCameraPhoto(data);
        }
        break;
    }

    case ACTION_OPEN_GALLERY: {
        if (resultCode == RESULT_OK) {
            Log.i("Huy", "onActivityResult: ACTION_OPEN_GALLERY");
            String filePath = data.getData().getPath();
            Log.i("Huy", "Path: " + filePath);
        }
        break;
    } // ACTION_OPEN_GALLERY
    } // switch
}

From source file:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_CANCELED) {
        switch (requestCode) {
        case PHOTO_REQUEST_CAMERA:// 
            // ????
            String state = Environment.getExternalStorageState();
            if (state.equals(Environment.MEDIA_MOUNTED)) {
                File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                File tempFile = new File(path, "newpic.jpg");
                startPhotoZoom(Uri.fromFile(tempFile));
            } else {
                Toast.makeText(activity, "??", Toast.LENGTH_SHORT)
                        .show();/*from  w w w . j  av a2s  .  c  om*/
            }
            break;
        case PHOTO_REQUEST_ALBUM:// 
            startPhotoZoom(data.getData());
            break;

        case PHOTO_REQUEST_CUT: // ??
            if (data != null) {
                getImageToView(data);
            }
            break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.afwsamples.testdpc.SetupManagementFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Activity activity = getActivity();/*w w  w .ja  v  a 2 s .  c  om*/

    switch (requestCode) {
    case REQUEST_PROVISION_MANAGED_PROFILE:
    case REQUEST_PROVISION_DEVICE_OWNER:
        if (resultCode == Activity.RESULT_OK) {
            // Success, finish the enclosing activity. NOTE: Only finish once we're done
            // here, as in synchronous auth cases we don't want the user to return to the
            // Android setup wizard or add-account flow prematurely.
            activity.setResult(Activity.RESULT_OK);
            activity.finish();
        } else {
            // Something went wrong (either provisioning failed, or the user backed out).
            // Let the user decide how to proceed.
            Toast.makeText(activity, R.string.provisioning_failed_or_cancelled, Toast.LENGTH_SHORT).show();
        }
        break;
    case REQUEST_GET_LOGO:
        if (data != null && data.getData() != null) {
            mLogoUri = data.getData();
            mLogoValue.setText(mLogoUri.getLastPathSegment());
            Util.updateImageView(getActivity(), mLogoPreviewView, mLogoUri);
        }
        break;
    }
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_CANCELED) { //"The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation." (quote from https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,%20int,%20android.content.Intent) )
        switch (requestCode) {
        case CHOOSE_IMAGE: {
            setBackgroundUri(data.getData());
        }//from w  ww . j a v a  2s.  c o m
        }
    }
}

From source file:com.krayzk9s.imgurholo.activities.ImgurLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    destroyed = false;//from   w w w.  ja v a2s  .c  o m
    if (getActionBar() != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null
            && intent.getData().toString().startsWith("http://imgur.com/a")) {
        String uri = intent.getData().toString();
        album = uri.split("/")[4];
        Log.d("album", album);
        Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
        fetcher.execute();
    } else if (Intent.ACTION_VIEW.equals(action)
            && intent.getData().toString().startsWith("http://imgur.com/gallery/")) {
        String uri = intent.getData().toString();
        final String album = uri.split("/")[4];
        if (album.length() == 5) {
            Log.d("album", album);
            Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
            fetcher.execute();
        } else if (album.length() == 7) {
            Log.d("image", album);
            Fetcher fetcher = new Fetcher(this, "/3/gallery/image/" + album, ApiCall.GET, null, apiCall, IMAGE);
            fetcher.execute();
        }
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("http://i.imgur")) {
        String uri = intent.getData().toString();
        final String image = uri.split("/")[3].split("\\.")[0];
        Log.d("image", image);
        Fetcher fetcher = new Fetcher(this, "/3/image/" + image, ApiCall.GET, null, apiCall, IMAGE);
        fetcher.execute();
    }
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.send_coins_fragment, container);

    payeeNameView = (TextView) view.findViewById(R.id.send_coins_payee_name);
    payeeOrganizationView = (TextView) view.findViewById(R.id.send_coins_payee_organization);
    payeeVerifiedByView = (TextView) view.findViewById(R.id.send_coins_payee_verified_by);

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override//from w ww. j  a  va2  s.  c o m
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                final Address address = paymentIntent.hasAddress() ? paymentIntent.getAddress()
                        : (validatedAddress != null ? validatedAddress.address : null);
                if (address != null)
                    actionMode = activity.startActionMode(new ReceivingAddressActionMode(address));
            } else {
                actionMode.finish();
            }
        }
    });

    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(config.getBtcPrefix());
    btcAmountView.setInputPrecision(config.getBtcMaxPrecision());
    btcAmountView.setHintPrecision(config.getBtcPrecision());
    btcAmountView.setShift(config.getBtcShift());

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);
    amountCalculatorLink.setExchangeDirection(config.getLastExchangeDirection());

    directPaymentEnableView = (CheckBox) view.findViewById(R.id.send_coins_direct_payment_enable);
    directPaymentEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (paymentIntent.isBluetoothPaymentUrl() && isChecked && !bluetoothAdapter.isEnabled()) {
                // ask for permission to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH);
            }
        }
    });

    directPaymentMessageView = (TextView) view.findViewById(R.id.send_coins_direct_payment_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            isAmountValid();

            if (everythingValid())
                handleGo();
            else
                requestFocusFirst();
        }
    });

    amountCalculatorLink.setNextFocusId(viewGo.getId());

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "mintcoin".equals(scheme)) {
            initStateFromBitcoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && Constants.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(Constants.MIMETYPE_PAYMENTREQUEST,
                    ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action)) && Constants.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = BitcoinIntegration.paymentRequestFromIntent(intent);

            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }

    return view;
}