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:edu.mit.mobile.android.locast.data.Sync.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (Intent.ACTION_SYNC.equals(intent.getAction())) {
            if (intent.getBooleanExtra(EXTRA_EXPLICIT_SYNC, false)) {
                mNotifiedUserAboutNetworkStatus = true;
                mShouldAlertUserOnSuccess = true;
            }//from   ww  w .  ja  va  2  s . com
            startSync(intent.getData(), intent.getExtras());
        } else if (ACTION_CANCEL_SYNC.equals(intent.getAction())) {
            stopSync();
        }
    } else {
        // restarted by system.
        startSync();
    }

    return START_NOT_STICKY;
}

From source file:com.piusvelte.sonet.core.StatusDialog.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
            mFilePath = intent.getStringExtra(Widgets.INSTANT_UPLOAD);
            Log.d(TAG, "upload photo?" + mFilePath);
        } else {/*from w w w  .  jav a2 s .c  om*/
            mData = intent.getData();
            if (mData != null) {
                mData = intent.getData();
                if (intent.hasExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS))
                    mRect = intent.getParcelableExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS);
                else
                    mRect = intent.getSourceBounds();
                Log.d(TAG, "data:" + mData.toString());
                // need to use a thread here to avoid anr
                mLoadingDialog = new ProgressDialog(this);
                mLoadingDialog.setMessage(getString(R.string.status_loading));
                mLoadingDialog.setCancelable(true);
                mLoadingDialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        if (mStatusLoader != null)
                            mStatusLoader.cancel(true);
                        finish();
                    }
                });
                mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                        new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                finish();
                            }
                        });
                mLoadingDialog.show();
                mStatusLoader = new StatusLoader();
                mStatusLoader.execute();
            }
        }
    }
    if (mFilePath != null) {
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.uploadprompt)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivityForResult(
                                Sonet.getPackageIntent(getApplicationContext(), SonetCreatePost.class)
                                        .putExtra(Widgets.INSTANT_UPLOAD, mFilePath),
                                RESULT_REFRESH);
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        StatusDialog.this.finish();
                    }
                }).create();
        mDialog.show();
    } else {
        // check if the dialog is still loading
        if (mFinish)
            finish();
        else if ((mLoadingDialog == null) || !mLoadingDialog.isShowing())
            showDialog();
    }
}

From source file:com.plugin.camera.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits.//from  ww  w.  j ava 2  s.com
 *
 * @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;
                }
            }
            //This if block is added to the plugin to solve the issue which was saving portrait images in landscape with -90 degree rotetion
            if (intent.getBooleanExtra("portrait", false)) {
                Matrix matrix = new Matrix();
                matrix.preRotate(90);
                try {
                    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
                            true);
                } catch (Exception e) {
                    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2,
                            matrix, true);
                    e.printStackTrace();
                }
            }

            // 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:org.peterbaldwin.vlcremote.app.PlaybackActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String host = intent.getStringExtra(Intents.EXTRA_REMOTE_HOST);
    if (host != null) {
        int port = intent.getIntExtra(Intents.EXTRA_REMOTE_PORT, 8080);
        String authority = host + ":" + port;
        changeServer(authority);/*w ww.j  a v  a2s .  co  m*/
    }

    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intents.ACTION_REMOTE_VIEW.equals(action)
            || Intents.ACTION_VIEW.equals(action)) {
        Uri data = intent.getData();
        if (data != null) {
            changeInput(data.toString());
        }
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        String input = intent.getStringExtra(SearchManager.QUERY);
        changeInput(input);
    }
}

From source file:com.ubuntuone.android.files.service.UpDownService.java

private void registerUploadCancelReceiver() {
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this);
    uploadCancelReceiver = new BroadcastReceiver() {
        @Override/*from w w w. j  a  va2  s.  c o m*/
        public void onReceive(Context context, Intent intent) {
            if (uploadCancelReceiver != null) {
                uploadCancelTrigger.onCancel();
            }
            Uri uri = intent.getData();
            if (uri == null) {
                // Cancel all uploads.
                uri = Uploads.CONTENT_URI;
            }
            TransferUtils.dequeue(contentResolver, uri);
        }
    };
    IntentFilter filter = new IntentFilter(ACTION_CANCEL_UPLOAD);
    bm.registerReceiver(uploadCancelReceiver, filter);
}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatchFileFragment.java

/**
 * {@inheritDoc}/*from   w ww . j a  v  a  2  s .c o  m*/
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case ACTIVITY_REQUEST_INPUT_FILE:
        if (data != null && resultCode == Activity.RESULT_OK) {
            onSelectedInputUri(data.getData());
        }
        break;
    case ACTIVITY_REQUEST_OUTPUT_FILE:
        if (data != null && resultCode == Activity.RESULT_OK) {
            onSelectedOutputUri(data.getData());
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.slim.turboeditor.activity.MainActivity.java

/**
 * Parses the intent//from   www .  j  a  v a2s .c  om
 */
private void parseIntent(Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)
            || Intent.ACTION_PICK.equals(action) && type != null) {
        Uri uri = intent.getData();
        File newFile = new File(uri.getPath());
        newFileToOpen(newFile, "");
    } else if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            newFileToOpen(null, intent.getStringExtra(Intent.EXTRA_TEXT));
        }
    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java

/**
 * Overriden method from Fragment. Sets the image and thumbnail in the comment being
 * edited to the user selected image. Is called automatically after the user
 * returns from selecting an image from either the camera or photo gallery.
 * /*from   w  w  w .j  av  a 2 s . c  o  m*/
 * @param requestCode The request code supplied to startActivityForResult.
 * @param resultCode The result code returned by the activity.
 * @param data The data returned by the activity.
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Bitmap image = null;
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == ImageHelper.REQUEST_CAMERA) {
            Bitmap imageBitmap = null;
            try {
                imageBitmap = BitmapFactory.decodeStream(
                        getActivity().getContentResolver().openInputStream(Uri.fromFile(imageFile)));
            } catch (FileNotFoundException e) {
                Toaster.toastShort("Error. Could not load image.");
            }
            image = scaleImage(imageBitmap);
        } else if (requestCode == ImageHelper.REQUEST_GALLERY) {
            Bitmap imageBitmap = null;
            try {
                imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(),
                        data.getData());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            image = scaleImage(imageBitmap);
        }
    }
    editComment.setImage(image);
    Bitmap imageThumb = ThumbnailUtils.extractThumbnail(image, 100, 100);
    editComment.setImageThumb(imageThumb);
}

From source file:com.karura.framework.plugins.Capture.java

/**
 * Called when the video view exits./*from w ww . ja  v a2s .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(final int requestCode, final int resultCode, final Intent intent) {
    final String callId = requestCallIdMap.get(requestCode);
    final ContentResolver cr = getContext().getContentResolver();

    if (callId == null) {
        return;
    }
    requestCallIdMap.remove(requestCode);

    runInBackground(new Runnable() {
        public void run() {
            // Result received okay
            if (resultCode == Activity.RESULT_OK) {

                // An audio clip was requested
                if (requestCode == CAPTURE_AUDIO) {
                    // Get the uri of the audio clip
                    Uri data = intent.getData();
                    // create a file object from the uri
                    results.put(createMediaFile(data));

                    // Send Uri back to JavaScript for listening to audio
                    resolveWithResult(callId, results);

                } else if (requestCode == CAPTURE_IMAGE) {
                    // For some reason if I try to do:
                    // Uri data = intent.getData();
                    // It crashes in the emulator and on my phone with a null pointer exception
                    // To work around it I had to grab the code from CameraLauncher.java
                    try {
                        // 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(MIME_TYPE, IMAGE_JPEG);
                        Uri uri = null;
                        try {
                            uri = cr.insert(EXTERNAL_CONTENT_URI, values);
                        } catch (UnsupportedOperationException e) {
                            Log.d(LOG_TAG, "Can't write to external media storage.");
                            try {
                                uri = cr.insert(INTERNAL_CONTENT_URI, values);
                            } catch (UnsupportedOperationException ex) {
                                Log.d(LOG_TAG, "Can't write to internal media storage.");
                                reject(callId, CAPTURE_INTERNAL_ERR,
                                        "Error capturing image - no media storage found.");
                                return;
                            }
                        }
                        FileInputStream fis = new FileInputStream(
                                DirectoryManager.getTempDirectoryPath(getContext()) + "/Capture.jpg");
                        OutputStream os = cr.openOutputStream(uri);
                        byte[] buffer = new byte[4096];
                        int len;
                        while ((len = fis.read(buffer)) != -1) {
                            os.write(buffer, 0, len);
                        }
                        os.flush();
                        os.close();
                        fis.close();

                        // Add image to results
                        results.put(createMediaFile(uri));

                        checkForDuplicateImage();

                        // Send Uri back to JavaScript for viewing image
                        resolveWithResult(callId, results);

                    } catch (IOException e) {
                        if (BuildConfig.DEBUG) {
                            e.printStackTrace();
                        }
                        reject(callId, CAPTURE_INTERNAL_ERR, "Error capturing image.");
                    }
                } else if (requestCode == CAPTURE_VIDEO) {
                    // Get the uri of the video clip
                    Uri data = intent.getData();
                    // create a file object from the uri
                    results.put(createMediaFile(data));

                    // Send Uri back to JavaScript for viewing video
                    resolveWithResult(callId, results);
                }
            }
            // if cancelled or something else
            else {
                // user canceled the action
                rejectWithError(callId, CAPTURE_NO_MEDIA_FILES, "Canceled.");
            }
        }
    });

}

From source file:com.ubuntuone.android.files.service.UpDownService.java

private void registerDownloadCancelReceiver() {
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this);
    downloadCancelReceiver = new BroadcastReceiver() {
        @Override/*w  w w  .  j av a  2  s .c o m*/
        public void onReceive(Context context, Intent intent) {
            if (downloadCancelTrigger != null) {
                downloadCancelTrigger.onCancel();
            }
            Uri uri = intent.getData();
            if (uri == null) {
                // Cancel all downloads.
                uri = Downloads.CONTENT_URI;
            }
            TransferUtils.dequeue(contentResolver, uri);
        }
    };
    IntentFilter filter = new IntentFilter(ACTION_CANCEL_DOWNLOAD);
    IntentFilter filterId = null;
    try {
        filterId = new IntentFilter(ACTION_CANCEL_DOWNLOAD, "*/*");
    } catch (MalformedMimeTypeException e) {
        // Not interested.
    }
    bm.registerReceiver(downloadCancelReceiver, filter);
    if (filterId != null) {
        bm.registerReceiver(downloadCancelReceiver, filterId);
    }
}