Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

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

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:com.ichi2.anki.NoteEditor.java

private void fetchIntentInformation(Intent intent) {
    Bundle extras = intent.getExtras();
    if (ACTION_CREATE_FLASHCARD.equals(intent.getAction())) {
        // mSourceLanguage = extras.getString(SOURCE_LANGUAGE);
        // mTargetLanguage = extras.getString(TARGET_LANGUAGE);
        mSourceText = new String[2];
        mSourceText[0] = extras.getString(SOURCE_TEXT);
        mSourceText[1] = extras.getString(TARGET_TEXT);
    } else {/*w  w  w.  ja va2 s  .  com*/
        String first;
        String second;
        if (extras.getString(Intent.EXTRA_SUBJECT) != null) {
            first = extras.getString(Intent.EXTRA_SUBJECT);
        } else {
            first = "";
        }
        if (extras.getString(Intent.EXTRA_TEXT) != null) {
            second = extras.getString(Intent.EXTRA_TEXT);
        } else {
            second = "";
        }
        // Some users add cards via SEND intent from clipboard. In this case SUBJECT is empty
        if (first.equals("")) {
            // Assume that if only one field was sent then it should be the front
            first = second;
            second = "";
        }
        Pair<String, String> messages = new Pair<String, String>(first, second);

        mSourceText = new String[2];
        mSourceText[0] = messages.first;
        mSourceText[1] = messages.second;
    }
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case addressCode:
        if (data != null) {
            Bundle bundle = data.getExtras();
            mAddress = (Address) bundle.getSerializable(AddressActivity.ADRESS_STR);
            ((TextView) findViewById(R.id.addr_tv)).setText(mAddress.toString());
        }/*from  w  w  w . jav  a2s. c o  m*/
        break;
    case insuranceCode:
        if (data != null) {
            Bundle bundle = data.getExtras();
            mInsuranceInfo = (InsuranceInfo) bundle.getSerializable(InsuranceInfoActivity.INSURANCE_STR);
            ((TextView) findViewById(R.id.insurance_tv)).setText(mInsuranceInfo.toString());
        }
        break;
    }
}

From source file:org.medcare.Dicom.DicomActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    Bundle locBundle = null;//from  w w w .j  a  va 2  s .  c o m
    if (intent != null)
        locBundle = intent.getExtras();
    if (locBundle != null) {
        switch (requestCode) {
        case SETTING_DIALOG:
            connectionSettings(locBundle);
            break;
        default:
            break;
        }
    }
}

From source file:flex.android.magiccube.activity.ActivityBattleMode.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CONNECT_DEVICE:
        // When DeviceListActivity returns with a device to connect
        if (resultCode == Activity.RESULT_OK) {
            // Get the device MAC address
            String address = data.getExtras().getString(ActivityClient.EXTRA_DEVICE_ADDRESS);
            // Get the BLuetoothDevice object
            BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
            // Attempt to connect to the device
            mChatService.connect(device);
        }/* ww w .  j a v a 2 s.c  om*/
        break;
    case REQUEST_ENABLE_BT:
        // When the request to enable Bluetooth returns
        if (resultCode == Activity.RESULT_OK) {
            // Bluetooth is now enabled, so set up a chat session
            setupChat();
            Intent intent = new Intent(this, ActivityTab.class);
            startActivityForResult(intent, REQUEST_SETTING);
        } else {
            // User did not enable Bluetooth or an error occured
            Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
            finish();
        }
        break;
    case REQUEST_SETTING:
        if (resultCode == Activity.RESULT_OK) {
            // Log.e("ok","ok");
            if (MagiccubePreference.GetPreference(MagiccubePreference.ServerOrClient, this) == 1) {
                /*
                 * if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent
                 * = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                 * startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
                 * // Otherwise, setup the chat session } else { if
                 * (mChatService == null) setupChat(); }
                 */
                if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
                    ensureDiscoverable();
                } else {
                    this.showWait("...");
                }
            } else if (MagiccubePreference.GetPreference(MagiccubePreference.ServerOrClient, this) == 0) {
                String address = this
                        .getSharedPreferences(MagiccubePreference.SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE)
                        .getString(MagiccubePreference.ServerAddress, "");
                // Get the BLuetoothDevice object
                BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
                // Attempt to connect to the device
                mChatService.connect(device);
            } else {
                finish();
            }
        }

        break;

    case REQUEST_DISCOVERABLE:
        // Log.e("resultCode", resultCode+"");
        if (resultCode > 0) {
            this.showWait("...");
        } else {
            mHandler.sendEmptyMessage(NOT_ENABLE_DISCOVERY);
        }
        break;
    }
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    switch (requestCode) {

    case Const.RequestCode.ADDRESS_SEARCH: {
        if (resultCode == Activity.RESULT_OK) {

            int type = intent.getExtras().getInt(Const.Bundle.TYPE);
            LocationData location = intent.getExtras().getParcelable(Const.Bundle.LOCATION);

            switch (type) {
            case SearchActivity.TYPE_PICKUP:
                setPickupAddress(location);
                break;
            case SearchActivity.TYPE_DROPOFF:
                setDropoffAddress(location);
                break;
            }//  w ww. ja v a2  s .  c  om

            updateAddresses();
            moveMapToLocation(location);
        }
    }
        break;

    default: {
        super.onActivityResult(requestCode, resultCode, intent);
    }
        break;
    }
}

From source file:com.devwang.logcabin.LogCabinMainActivity.java

@SuppressLint({ "NewApi", "NewApi" })
private void connectDevice(Intent data, boolean secure) {
    // Get the device MAC address
    String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
    // Get the BLuetoothDevice object
    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    // Attempt to connect to the device
    mChatService.connect(device, secure);
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * Handle message intent filter for attachments
 * /* w w w  .  java  2s  .  c  o  m*/
 * @param intent
 */
private void handleIntentFilter(Intent intent) {
    attachments_type.put(ATTACHMENT_TYPE.IMAGE, "image/*");
    attachments_type.put(ATTACHMENT_TYPE.TEXT_FILE, "application/*");

    String action = intent.getAction();
    String type = intent.getType();

    // Single attachment
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        file_uris.add(fileUri);
        handleReceivedFile();
    }

    // Multiple Attachments
    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        file_uris.addAll(fileUris);
        handleReceivedFile();

    }

    // note.note send as mail
    if (intent.hasExtra("note_body")) {
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        String body = intent.getExtras().getString("note_body");
        edtBody.setText(HTMLHelper.stringToHtml(body));
        is_note_body = true;
    }

}

From source file:com.tealeaf.TeaLeaf.java

protected void onActivityResult(int request, int result, Intent data) {
    super.onActivityResult(request, result, data);
    PluginManager.callAll("onActivityResult", request, result, data);
    logger.log("GOT ACTIVITY RESULT WITH", request, result);

    switch (request) {
    case PhotoPicker.CAPTURE_IMAGE:
        if (result == RESULT_OK) {
            EventQueue.pushEvent(new PhotoBeginLoadedEvent());
            Bitmap bmp = null;//from  ww  w .ja v  a 2  s  . com

            if (data != null) {
                Bundle extras = data.getExtras();
                //try and get bitmap off of intent
                if (extras != null) {
                    bmp = (Bitmap) extras.get("data");
                }

            }

            //try the large file on disk
            final File f = PhotoPicker.getCaptureImageTmpFile();
            if (f != null && f.exists()) {
                new Thread(new Runnable() {
                    public void run() {
                        Bitmap bmp = null;
                        String filePath = f.getAbsolutePath();

                        try {
                            bmp = BitmapFactory.decodeFile(filePath);
                        } catch (OutOfMemoryError e) {
                            System.gc();
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inSampleSize = 4;
                            bmp = BitmapFactory.decodeFile(filePath, options);
                        }

                        if (bmp != null) {
                            try {
                                File f = new File(filePath);
                                ExifInterface exif = new ExifInterface(f.getAbsolutePath());
                                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                                        ExifInterface.ORIENTATION_NORMAL);
                                if (orientation != ExifInterface.ORIENTATION_NORMAL) {
                                    int rotateBy = 0;
                                    switch (orientation) {
                                    case ExifInterface.ORIENTATION_ROTATE_90:
                                        rotateBy = ROTATE_90;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_180:
                                        rotateBy = ROTATE_180;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_270:
                                        rotateBy = ROTATE_270;
                                        break;
                                    }
                                    Bitmap rotatedBmp = rotateBitmap(bmp, rotateBy);
                                    if (rotatedBmp != bmp) {
                                        bmp.recycle();
                                    }
                                    bmp = rotatedBmp;
                                }
                            } catch (Exception e) {
                                logger.log(e);
                            }
                            f.delete();

                            if (bmp != null) {
                                glView.getTextureLoader()
                                        .saveCameraPhoto(glView.getTextureLoader().getCurrentPhotoId(), bmp);
                                glView.getTextureLoader().finishCameraPicture();
                            } else {
                                glView.getTextureLoader().failedCameraPicture();
                            }
                        }
                    }
                }).start();

            } else {
                glView.getTextureLoader().saveCameraPhoto(glView.getTextureLoader().getCurrentPhotoId(), bmp);
                glView.getTextureLoader().finishCameraPicture();
            }
        } else {
            glView.getTextureLoader().failedCameraPicture();
        }
        break;
    case PhotoPicker.PICK_IMAGE:
        if (result == RESULT_OK) {
            final Uri selectedImage = data.getData();
            EventQueue.pushEvent(new PhotoBeginLoadedEvent());

            String[] filePathColumn = { MediaColumns.DATA, MediaStore.Images.ImageColumns.ORIENTATION };

            String _filepath = null;

            try {
                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                _filepath = cursor.getString(columnIndex);
                columnIndex = cursor.getColumnIndex(filePathColumn[1]);
                int orientation = cursor.getInt(columnIndex);
                cursor.close();
            } catch (Exception e) {

            }

            final String filePath = _filepath;

            new Thread(new Runnable() {
                public void run() {
                    if (filePath == null) {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        InputStream inputStream;
                        Bitmap bmp = null;

                        try {
                            inputStream = getContentResolver().openInputStream(selectedImage);
                            bmp = BitmapFactory.decodeStream(inputStream, null, options);
                            inputStream.close();
                        } catch (Exception e) {
                            logger.log(e);

                        }

                        if (bmp != null) {
                            glView.getTextureLoader()
                                    .saveGalleryPicture(glView.getTextureLoader().getCurrentPhotoId(), bmp);
                            glView.getTextureLoader().finishGalleryPicture();
                        } else {
                            glView.getTextureLoader().failedGalleryPicture();
                        }

                    } else {
                        Bitmap bmp = null;

                        try {
                            bmp = BitmapFactory.decodeFile(filePath);
                        } catch (OutOfMemoryError e) {
                            System.gc();
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inSampleSize = 4;
                            bmp = BitmapFactory.decodeFile(filePath, options);
                        }

                        if (bmp != null) {
                            try {
                                File f = new File(filePath);
                                ExifInterface exif = new ExifInterface(f.getAbsolutePath());
                                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                                        ExifInterface.ORIENTATION_NORMAL);
                                if (orientation != ExifInterface.ORIENTATION_NORMAL) {
                                    int rotateBy = 0;
                                    switch (orientation) {
                                    case ExifInterface.ORIENTATION_ROTATE_90:
                                        rotateBy = ROTATE_90;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_180:
                                        rotateBy = ROTATE_180;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_270:
                                        rotateBy = ROTATE_270;
                                        break;
                                    }
                                    Bitmap rotatedBmp = rotateBitmap(bmp, rotateBy);
                                    if (rotatedBmp != bmp) {
                                        bmp.recycle();
                                    }
                                    bmp = rotatedBmp;
                                }
                            } catch (Exception e) {
                                logger.log(e);
                            }

                            if (bmp != null) {
                                glView.getTextureLoader()
                                        .saveGalleryPicture(glView.getTextureLoader().getCurrentPhotoId(), bmp);
                                glView.getTextureLoader().finishGalleryPicture();
                            } else {
                                glView.getTextureLoader().failedGalleryPicture();
                            }
                        }
                    }
                }
            }).start();

        } else {
            glView.getTextureLoader().failedGalleryPicture();
        }
        break;
    }
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

private void photoSucess(Intent intent) {
    //URI????URI?URI??
    //???try-catch???
    Uri uri = intent.getData();//from   ww w.  j  a v a  2 s  . c om
    if (null == uri) {
        uri = mImageUri;
    }
    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.kjsaw.alcosys.ibacapp.IBAC.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    _inDialog = false;// w  ww  .  ja  v  a 2s. c  om
    switch (requestCode) {
    case REQUEST_CONNECT_DEVICE:
        // When DeviceListActivity returns with a device to connect
        _conversationArrayAdapter.clear();
        if (resultCode == Activity.RESULT_OK) {

            // Get the device MAC address
            bluetoothMACAddress = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);

            // Get the BLuetoothDevice object
            BluetoothDevice device = _bluetoothAdapter.getRemoteDevice(bluetoothMACAddress);
            unpairDevice(device);
            pairDevice(device);
            // Attempt to connect to the device
            _iBACservice.connect(device);
        } else if (resultCode == Constant.RESULT_ERROR_MORE_IBAC) {
            _conversationArrayAdapter.add(getResources().getString(R.string.error_more_ibac));
            ShutdownAction shutdownAction = new ShutdownAction(_handler, 3, true);
            shutdownAction.Invoke(null);
        } else {
            if (ApplicationConstants.DebugMode)
                Log.d(TAG, "No devices found");

            _conversationArrayAdapter.add(getResources().getString(R.string.none_found));
            ShutdownAction shutdownAction = new ShutdownAction(_handler, 3, true);
            shutdownAction.Invoke(null);
        }
        break;
    case REQUEST_ENABLE_BT:
        if (resultCode == Activity.RESULT_OK) {
            _isConfiguringPhone = false;
            InitializeAllServices();
        } else {
            // User did not enable Bluetooth or an error occured
            if (ApplicationConstants.DebugMode)
                Log.d(ApplicationConstants.ApplicationTag, "Bluetooth is not enabled");

            _handler.obtainMessage(IBAC.ADD_MESSAGE, getResources().getString(R.string.bt_not_enabled_leaving))
                    .sendToTarget();

            ShutdownAction shutdownAction = new ShutdownAction(_handler, 3, true);
            shutdownAction.Invoke(null);
        }
        break;
    case ApplicationConstants.CALIBRATION:
        switch (resultCode) {
        case ApplicationConstants.REQUEST_CALIBRATE:
            if (_iBACservice._messageProcessor.GetState() == MessageProcessorStates.NotConnected) {
                _handler.obtainMessage(CALIBRATION_ABORTED_NO_CONNECTION, null).sendToTarget();
            } else {
                try {
                    _iBACservice._messageProcessor.SendMessage(Messages.RequestCalibration);
                    _handler.obtainMessage(CALIBRATING, null).sendToTarget();
                } catch (Exception e) {
                    Log.e(ApplicationConstants.ApplicationTag,
                            "Failed to send calibration message: " + ExceptionHelper.GetTypeIfMessageEmpty(e));
                }
            }

            break;
        case ApplicationConstants.ACTIVITY_ABORT:
            if (_iBACservice._messageProcessor.GetState() == MessageProcessorStates.NotConnected) {
                _handler.obtainMessage(CALIBRATION_ABORTED_NO_CONNECTION, null).sendToTarget();
            } else {
                _handler.obtainMessage(CALIBRATION_ABORTED, null).sendToTarget();
            }
            break;
        default:
            break;
        }
        break;
    // case REQUEST_ENABLE_GPS:
    // deviceLocation.runGPS();
    // initBluetooth();
    // break;
    default:
        break;
    }
}