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.snipme.record.Record.java

/**
 * Called when the video view exits.//from   w w w . ja  v  a 2  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").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == CAPTURE_VIDEO) {
            Log.i(TAG, "onActivityResult: Video Capture success");
            final Record that = this;
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null) {
                        // Get the uri of the video clip
                        data = intent.getData();
                        Log.i(TAG, "onActivityResult: Uri: " + data);
                        Log.i(TAG, "Uri of the video file recorded");
                    }

                    if (data == null) {
                        File movie = new File(getTempDirectoryPath(), "Capture.avi");
                        data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if (data == null) {
                        that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    } else {
                        results.put(createMediaFile(data));

                        if (results.length() >= 1) {
                            // Send Uri back to JavaScript for viewing video
                            that.callbackContext
                                    .sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                        } else {
                            // still need to capture more video clips
                            //captureVideo(duration);
                        }
                    }
                }
            };
            this.cordova.getThreadPool().execute(captureVideo);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {

    }

}

From source file:it.feio.android.omninotes.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case SPRINGPAD_IMPORT:
            Uri filesUri = intent.getData();
            String path = FileHelper.getPath(getActivity(), filesUri);
            // An IntentService will be launched to accomplish the import task
            Intent service = new Intent(getActivity(), DataBackupIntentService.class);
            service.setAction(DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD);
            service.putExtra(DataBackupIntentService.EXTRA_SPRINGPAD_BACKUP, path);
            getActivity().startService(service);
            break;

        case RINGTONE_REQUEST_CODE:
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String notificationSound = uri == null ? null : uri.toString();
            prefs.edit().putString("settings_notification_ringtone", notificationSound).apply();
            break;
        }/* ww w  . j  a  va2  s.co m*/
    }
}

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

/**
 * ???? ???????//  www  . ja v  a  2 s  .  c  o  m
 *
 * @param intent
 */
private void startCutPhotoAfterCamera(Intent intent) {
    // mDstTypeFILE_URIintentnull?mImageUri
    if (null != intent && null != intent.getData()) {
        startCutPhoto(intent.getData());
    } else {
        startCutPhoto(mImageUri);
    }
}

From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Const.REQUEST_CODE_CAMERA) { // ?
        if (cameraFile.exists()) {
            refreshImage(cameraFile.getPath());
        }/*from w  w  w.  jav  a  2 s  . co  m*/

    } else if (requestCode == Const.REQUEST_CODE_GALLERY) { // 
        if (data != null) {
            Uri imgUri = data.getData();
            String imgPath = ImageUtil.getImageAbsolutePath(this, imgUri);
            if (!TextUtils.isEmpty(imgPath) && new File(imgPath).exists()) {
                refreshImage(imgPath);
            }
        }
    }
}

From source file:com.doplgangr.secrecy.settings.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_SET_VAULT_ROOT:
        // If the file selection was successful
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                // Get the URI of the selected file
                final Uri uri = data.getData();
                try {
                    // Get the file path from the URI
                    final String path = FileUtils.getPath(context, uri);
                    Storage.setRoot(path);
                    Preference vault_root = findPreference(Config.VAULT_ROOT);
                    vault_root.setSummary(Storage.getRoot().getAbsolutePath());
                } catch (Exception e) {
                    Log.e("SettingsFragment", "File select error", e);
                }// ww w.  j a va  2 s.  co m
            }
        }
        break;
    case REQUEST_CODE_MOVE_VAULT:
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                // Get the URI of the selected file
                final Uri uri = data.getData();
                try {
                    // Get the file path from the URI
                    final String path = FileUtils.getPath(context, uri);
                    if (path.contains(Storage.getRoot().getAbsolutePath())) {
                        Util.alert(context, getString(R.string.Settings__cannot_move_vault),
                                getString(R.string.Settings__cannot_move_vault_message),
                                Util.emptyClickListener, null);
                        break;
                    }
                    Util.alert(context, getString(R.string.Settings__move_vault),
                            String.format(getString(R.string.move_message), Storage.getRoot().getAbsolutePath(),
                                    path),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    String[] children = new File(path).list();
                                    if (children.length == 0) {
                                        final ProgressDialog progressDialog = ProgressDialog.show(context, null,
                                                context.getString(R.string.Settings__moving_vault), true);
                                        new Thread(new Runnable() {
                                            public void run() {
                                                moveStorageRoot(path, progressDialog);
                                            }
                                        }).start();
                                    } else
                                        Util.alert(context, getString(R.string.Error__files_exist),
                                                getString(R.string.Error__files_exist_message),
                                                Util.emptyClickListener, null);
                                }
                            }, Util.emptyClickListener);
                } catch (Exception e) {
                    Log.e("SettingsFragment", "File select error", e);
                }
            }
        }
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.dycody.android.idealnote.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case SPRINGPAD_IMPORT:
            Uri filesUri = intent.getData();
            String path = FileHelper.getPath(getActivity(), filesUri);
            // An IntentService will be launched to accomplish the import task
            Intent service = new Intent(getActivity(), DataBackupIntentService.class);
            service.setAction(DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD);
            service.putExtra(DataBackupIntentService.EXTRA_SPRINGPAD_BACKUP, path);
            getActivity().startService(service);
            break;

        case RINGTONE_REQUEST_CODE:
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String notificationSound = uri == null ? null : uri.toString();
            prefs.edit().putString("settings_notification_ringtone", notificationSound).apply();
            break;

        default://from   w w  w.  jav  a 2 s  . c  om
            Log.e(Constants.TAG, "Wrong element choosen: " + requestCode);
        }
    }
}

From source file:com.firesoft.member.Activity.F9_SettingActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_CAMERA) {
            File files = new File(mFileName);
            if (files.exists()) {
                mImagePath = mFileName;//from   w  w w .jav a  2  s .  c o  m
                mImagePath = startPhotoZoom(Uri.fromFile(new File(mImagePath)));
            }
        } else if (requestCode == REQUEST_PHOTO) {
            Uri selectedImage = data.getData();
            mImagePath = startPhotoZoom(selectedImage);
        }
    }
}

From source file:com.zira.registration.DocumentUploadActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        String imagePath = "";

        if (requestCode == 1) {
            encodedImage = "";
            imagePath = mCurrentPhotoPath;
        } else if (requestCode == 2) {
            encodedImage = "";
            Uri selectedImageUri = data.getData();

            Cursor cursor = getContentResolver().query(selectedImageUri,
                    new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
            cursor.moveToFirst();// w w w.jav a2  s.  c o m

            //Link to the image
            final String imageFilePath = cursor.getString(0);
            cursor.close();
            imagePath = imageFilePath;
        }

        if (trigger.equals("vehicle")) {
            encodedImage = Util.showImage(imagePath, vehicleImage);
        } else if (trigger.equals("rc")) {
            encodedImage = Util.showImage(imagePath, RCImage);
        } else if (trigger.equals("drivinglicense")) {
            encodedImage = Util.showImage(imagePath, licenceImage);
        } else if (trigger.equals("medicalcertificate")) {
            encodedImage = Util.showImage(imagePath, medicalImage);
        }

        try {
            if (Util.isNetworkAvailable(DocumentUploadActivity.this)) {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                nameValuePairs.add(new BasicNameValuePair("RiderId", prefs.getString("riderid", null)));
                nameValuePairs.add(new BasicNameValuePair("Trigger", trigger));
                nameValuePairs.add(new BasicNameValuePair("Image", encodedImage));

                Log.e("IMAGEUPLOAD", nameValuePairs.toString());
                AsyncTaskForZira mUploadImage = new AsyncTaskForZira(DocumentUploadActivity.this,
                        uploadImageMethod, nameValuePairs, false, "");
                mUploadImage.delegate = (AsyncResponseForZira) DocumentUploadActivity.this;
                mUploadImage.execute();
            } else {
                Util.alertMessage(DocumentUploadActivity.this, "Please check your internet connection");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_CAMERA) {
            File files = new File(mFileName);
            if (files.exists()) {
                mImagePath = mFileName;/*w  w w  .ja va  2s.  com*/
                mImagePath = startPhotoZoom(Uri.fromFile(new File(mImagePath)));
            }
        } else if (requestCode == REQUEST_PHOTO) {
            Uri selectedImage = data.getData();
            mImagePath = startPhotoZoom(selectedImage);
        } else if (requestCode == REQUEST_PHOTOZOOM) {
            File f = new File(mImagePath);
            if (f.exists()) {
                File file = new File(ImageUtil.zoomImage(mImagePath, 350));
                mUserBalance.changeAvatar(file);
            } else {
                ToastView toast = new ToastView(this, getString(R.string.photo_not_exsit));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        }
    }
}