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.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.e("Activity sss1", "sds");
    if (requestCode == GALLERY_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                uri = data.getData();
                image_path = uri.getPath();
                addNewVehicalFragment.setImagePath(image_path);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                try {
                    // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
                    options.inSampleSize = calculateInSampleSize(options, 100, 100);
                    options.inJustDecodeBounds = false;
                    Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null,
                            options);/* w  w  w .jav  a 2 s.c  o m*/
                    // File mm=new File(image_path);
                    car_image.setImageBitmap(image);
                    car_image1.setImageBitmap(image);

                    Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
                    /* ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                     File destination = new File(getCacheDir(),"car.jpg");
                     FileOutputStream fo;
                     try {
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                     } catch (IOException e) {
                    e.printStackTrace();
                     }
                     image_path=destination.getAbsolutePath();
                    // car_image.setImageBitmap(bitmap);
                     addNewVehicalFragment.setImagePath(image_path);*/

                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    } else if (requestCode == CAMERA_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data.hasExtra("data")) {
                Bitmap bitmap = (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                File destination = new File(getCacheDir(), "car.jpg");
                FileOutputStream fo;
                try {
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                image_path = destination.getAbsolutePath();
                car_image.setImageBitmap(bitmap);
                car_image1.setImageBitmap(bitmap);
                addNewVehicalFragment.setImagePath(image_path);
            } else if (data.getExtras() == null) {

                Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

                BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath());
                //img_view_drivingLicense.setImageDrawable(thumbnail);
                car_image.setImageDrawable(thumbnail);
                car_image1.setImageDrawable(thumbnail);

            }

        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    } else {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null && AddNewVehicalFragment.scanFlag) {
            AddNewVehicalFragment.scanFlag = false;
            if (result.getContents() == null) {
                finish();
                Toast.makeText(AddVehicalAndPayment.this, "Cancelled", Toast.LENGTH_LONG).show();

            } else {
                //Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
                //scan_txt.setText(""+result.getContents());
                Log.e("result", result.getContents());
                // getVinNumber(result.getContents());
                vin_number = result.getContents();
                getVinNumber(vin_number);

            }
        }
    }
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if the user chose a image to be sent to the current buddy
    if (requestCode == ADD_PHOTO_CLICKED && resultCode == Activity.RESULT_OK) {
        if (data.getData() != null) {
            // one image was selected
            Message msg = new Message(data.getData());
            images.add(msg);//from w w w.  j a  v a2 s  . c  o m
            current = images.size() - 1;
        } else if (data.getClipData() != null) {
            // multiple images were selected
            ClipData clipData = data.getClipData();
            for (int i = 0; i < clipData.getItemCount(); i++)
                images.add(new Message(clipData.getItemAt(i).getUri()));
            current = images.size() - 1;
        }
    }
}

From source file:com.tealeaf.TeaLeaf.java

private void getLaunchType(Intent intent) {
    Uri data = intent.getData();
    LaunchTypeEvent event;//  www  . j a v a 2  s . c  o m
    //launch type "notification" has been taken out
    if (data != null) {
        logger.log("{tealeaf} Launched with intent url:", data.toString());
        event = new LaunchTypeEvent("url", data.toString());
    } else {
        event = new LaunchTypeEvent("standard");
    }
    EventQueue.pushEvent(event);
}

From source file:com.farmerbb.notepad.activity.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*from  ww w.  j  ava 2s .co m*/
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {

    if (resultCode == RESULT_OK && resultData != null) {
        successful = true;

        if (requestCode == IMPORT) {
            Uri uri = resultData.getData();
            ClipData clipData = resultData.getClipData();

            if (uri != null)
                successful = importNote(uri);
            else if (clipData != null)
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    successful = importNote(clipData.getItemAt(i).getUri());
                }

            // Show toast notification
            showToast(successful
                    ? (uri == null ? R.string.notes_imported_successfully : R.string.note_imported_successfully)
                    : R.string.error_importing_notes);

            // Send broadcast to NoteListFragment to refresh list of notes
            Intent listNotesIntent = new Intent();
            listNotesIntent.setAction("com.farmerbb.notepad.LIST_NOTES");
            LocalBroadcastManager.getInstance(this).sendBroadcast(listNotesIntent);
        } else if (requestCode == EXPORT) {
            try {
                saveExportedNote(loadNote(filesToExport[fileBeingExported].toString()), resultData.getData());
            } catch (IOException e) {
                successful = false;
            }

            fileBeingExported++;
            if (fileBeingExported < filesToExport.length)
                reallyExportNotes();
            else
                showToast(successful
                        ? (fileBeingExported == 1 ? R.string.note_exported_to : R.string.notes_exported_to)
                        : R.string.error_exporting_notes);

            File fileToDelete = new File(getFilesDir() + File.separator + "exported_note");
            fileToDelete.delete();
        } else if (requestCode == EXPORT_TREE) {
            DocumentFile tree = DocumentFile.fromTreeUri(this, resultData.getData());

            for (Object exportFilename : filesToExport) {
                try {
                    DocumentFile file = tree.createFile("text/plain",
                            generateFilename(loadNoteTitle(exportFilename.toString())));

                    if (file != null)
                        saveExportedNote(loadNote(exportFilename.toString()), file.getUri());
                    else
                        successful = false;
                } catch (IOException e) {
                    successful = false;
                }
            }

            showToast(successful ? R.string.notes_exported_to : R.string.error_exporting_notes);
        }
    }
}

From source file:ca.ualberta.app.activity.CreateAnswerActivity.java

/**
 * Display the selected photo in the answer, and notify the user if the
 * operation is successful/*from w  w w. j ava 2s .  co  m*/
 * 
 * @param requestCode
 *            A code that represents the activity of adding an image.
 * @param resultCode
 *            A code that represent if the image adding process is
 *            committed/canceled.
 * @param Intent
 *            data The data.
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            String imagePath = imageFileUri.getPath();

            if (saveImageView(imagePath)) {
                setImageView();
            } else {
                refuseUpdatePic();
            }
        }
        if (requestCode == GET_IMAGE_ACTIVITY_REQUEST_CODE) {

            String imagePath = getPath(this, data.getData());
            if (saveImageView(imagePath)) {
                setImageView();
            } else {
                refuseUpdatePic();
            }
        }
    } else if (resultCode == RESULT_CANCELED) {
        Toast.makeText(this, "Photo Canceled!", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Have no idea what happened!", Toast.LENGTH_SHORT).show();
    }

}

From source file:android_network.hetnet.vpn_service.ActivityLog.java

private void handleExportPCAP(final Intent data) {
    new AsyncTask<Object, Object, Throwable>() {
        @Override/*  w  ww .jav  a2s  .c  o m*/
        protected Throwable doInBackground(Object... objects) {
            OutputStream out = null;
            FileInputStream in = null;
            try {
                // Stop capture
                ServiceSinkhole.setPcap(false, ActivityLog.this);

                Uri target = data.getData();
                if (data.hasExtra("org.openintents.extra.DIR_PATH"))
                    target = Uri.parse(target + "/netguard.pcap");
                Log.i(TAG, "Export PCAP URI=" + target);
                out = getContentResolver().openOutputStream(target);

                File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
                in = new FileInputStream(pcap);

                int len;
                long total = 0;
                byte[] buf = new byte[4096];
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                    total += len;
                }
                Log.i(TAG, "Copied bytes=" + total);

                return null;
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                return ex;
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }
                if (in != null)
                    try {
                        in.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }

                // Resume capture
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityLog.this);
                if (prefs.getBoolean("pcap", false))
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
            }
        }

        @Override
        protected void onPostExecute(Throwable ex) {
            if (ex == null)
                Toast.makeText(ActivityLog.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(ActivityLog.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
    }.execute();
}

From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java

private void onSelectFromGalleryResult(Intent data) {
    if (tempMechanismViewId != -1
            && allMechanismViews.get(tempMechanismViewId) instanceof ScreenshotMechanismView) {
        ScreenshotMechanismView screenshotMechanismView = (ScreenshotMechanismView) allMechanismViews
                .get(tempMechanismViewId);
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();/*w w  w .jav a 2  s. c o m*/
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String tempPicturePath = cursor.getString(columnIndex);
            cursor.close();
            screenshotMechanismView.setPicturePath(tempPicturePath);
            screenshotMechanismView.setAnnotatedImagePath(tempPicturePath);
            Bitmap tempPictureBitmap = BitmapFactory.decodeFile(tempPicturePath);
            screenshotMechanismView.setPictureBitmap(tempPictureBitmap);
            screenshotMechanismView.getScreenShotPreviewImageView().setBackground(null);
            screenshotMechanismView.getScreenShotPreviewImageView().setImageBitmap(tempPictureBitmap);
            screenshotMechanismView.getAnnotateScreenshotButton().setEnabled(true);
            screenshotMechanismView.getDeleteScreenshotButton().setEnabled(true);
        }
        tempMechanismViewId = -1;
    }
}

From source file:com.nonstop.android.SoC.Facebook.Hackbook.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    /*/*from ww w.  j  a va  2  s  . c om*/
     * if this is the activity result from authorization flow, do a call
     * back to authorizeCallback Source Tag: login_tag
     */
    case AUTHORIZE_ACTIVITY_RESULT_CODE: {
        Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
        break;
    }
    /*
     * if this is the result for a photo picker from the gallery, upload
     * the image after scaling it. You can use the Utility.scaleImage()
     * function for scaling
     */
    case PICK_EXISTING_PHOTO_RESULT_CODE: {
        if (resultCode == Activity.RESULT_OK) {
            Uri photoUri = data.getData();
            if (photoUri != null) {
                Bundle params = new Bundle();
                try {
                    params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                params.putString("caption", "NonstopSoC");
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
            } else {
                Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.",
                        Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show();
        }
        break;

    }
    }

}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (resultCode != RESULT_OK)
        return;/*  w w  w.  ja  v a 2  s .c  o  m*/

    switch (requestCode) {
    case SELECT_FILE_REQ:
        // clear previous data
        mFilePath = null;
        mFileStreamUri = null;

        // and read new one
        final Uri uri = data.getData();
        /*
         * The URI returned from application may be in 'file' or 'content' schema.
         * 'File' schema allows us to create a File object and read details from if directly.
         * 
         * Data from 'Content' schema must be read by Content Provider. To do that we are using a Loader.
         */
        if (uri.getScheme().equals("file")) {
            // the direct path to the file has been returned
            final String path = uri.getPath();
            final File file = new File(path);
            mFilePath = path;

            mFileNameView.setText(file.getName());
            mFileSizeView.setText(getString(R.string.dfu_file_size_text, file.length()));
            final boolean isHexFile = mStatusOk = MimeTypeMap.getFileExtensionFromUrl(path)
                    .equalsIgnoreCase("HEX");
            mFileStatusView.setText(isHexFile ? R.string.dfu_file_status_ok : R.string.dfu_file_status_invalid);
            mUploadButton.setEnabled(mSelectedDevice != null && isHexFile);
        } else if (uri.getScheme().equals("content")) {
            // an Uri has been returned
            mFileStreamUri = uri;
            // if application returned Uri for streaming, let's us it. Does it works?
            // FIXME both Uris works with Google Drive app. Why both? What's the difference? How about other apps like DropBox?
            final Bundle extras = data.getExtras();
            if (extras != null && extras.containsKey(Intent.EXTRA_STREAM))
                mFileStreamUri = extras.getParcelable(Intent.EXTRA_STREAM);

            // file name and size must be obtained from Content Provider
            final Bundle bundle = new Bundle();
            bundle.putParcelable(EXTRA_URI, uri);
            getSupportLoaderManager().restartLoader(0, bundle, this);
        }
        break;
    default:
        break;
    }
}

From source file:net.sf.asap.PlayerService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    registerReceiver(headsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
    registerMediaButtonEventReceiver("registerMediaButtonEventReceiver");

    TelephonyManager telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListener() {
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING)
                pause();/*from w  w w  . j a va  2 s.co m*/
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);

    Uri uri = intent.getData();
    String playlistUri = intent.getStringExtra(EXTRA_PLAYLIST);
    if (playlistUri != null)
        setPlaylist(Uri.parse(playlistUri), false);
    else if ("file".equals(uri.getScheme())) {
        if (ASAPInfo.isOurFile(uri.toString()))
            setPlaylist(Util.getParent(uri), false);
        else {
            setPlaylist(uri, true);
            uri = playlist.get(0);
        }
    }
    playFile(uri, SONG_DEFAULT);
}