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:cn.zsmy.akm.doctor.profile.fragment.DoctorLicenseFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != -1 && null != data) {
        return;//from   ww  w .  j av a2s  . com
    }
    Uri uri = null;
    if (data != null && data.getData() != null) {
        uri = data.getData();
    }
    switch (requestCode) {
    case CARD_ONE_PIC:
        if (PHOTO_CREAME == CREAME) {
            if (uri == null) {
                uri = tempUri;
                picturePath = SystemPhoto.getFilePathFromUri(getActivity(), uri);
            }
        } else if (PHOTO_CREAME == PHOTO) {
            picturePath = StringUtils.getFilePath(getActivity(), data);
        }

        if (picturePath != null) {
            urlDatas.set(0, picturePath);
            Bitmap bitmap = ImageUtils.zoomDrawable(ImageUtils.resizePhoto(getActivity(), picturePath),
                    card_1.getWidth(), card_1.getHeight());
            if (bitmap != null) {
                card_1.setBackgroundDrawable(ImageUtils.resizePhoto(getActivity(), picturePath));
                card_1.setImageBitmap(null);
                photoPopupWindow.dismiss();
            }
        }
        break;
    case CARD_TOW_PIC:
        if (PHOTO_CREAME == CREAME) {
            if (uri == null) {
                uri = tempUri;
                picturePath = SystemPhoto.getFilePathFromUri(getActivity(), uri);
            }
        } else if (PHOTO_CREAME == PHOTO) {
            picturePath = StringUtils.getFilePath(getActivity(), data);
        }

        if (picturePath != null) {
            urlDatas.set(1, picturePath);
            Bitmap bitmap = ImageUtils.zoomDrawable(ImageUtils.resizePhoto(getActivity(), picturePath),
                    card_2.getWidth(), card_2.getHeight());
            if (bitmap != null) {
                card_2.setBackgroundDrawable(ImageUtils.resizePhoto(getActivity(), picturePath));
                card_2.setImageBitmap(null);
                photoPopupWindow.dismiss();
            }
        }
        break;
    case DOCTOR_CARD_ONE_PIC:
        if (PHOTO_CREAME == CREAME) {
            if (uri == null) {
                uri = tempUri;
                picturePath = SystemPhoto.getFilePathFromUri(getActivity(), uri);
            }
        } else if (PHOTO_CREAME == PHOTO) {
            picturePath = StringUtils.getFilePath(getActivity(), data);
        }

        if (picturePath != null) {
            urlDatas.set(2, picturePath);
            Bitmap bitmap = ImageUtils.zoomDrawable(ImageUtils.resizePhoto(getActivity(), picturePath),
                    doctor_card_1.getWidth(), doctor_card_1.getHeight());
            if (bitmap != null) {
                doctor_card_1.setBackgroundDrawable(ImageUtils.resizePhoto(getActivity(), picturePath));
                doctor_card_1.setImageBitmap(null);
                photoPopupWindow.dismiss();
            }
        }
        break;
    case DOCTOR_CARD_TOW_PIC:
        if (PHOTO_CREAME == CREAME) {
            if (uri == null) {
                uri = tempUri;
                picturePath = SystemPhoto.getFilePathFromUri(getActivity(), uri);
            }
        } else if (PHOTO_CREAME == PHOTO) {
            picturePath = StringUtils.getFilePath(getActivity(), data);
        }

        if (picturePath != null) {
            urlDatas.set(3, picturePath);
            Bitmap bitmap = ImageUtils.zoomDrawable(ImageUtils.resizePhoto(getActivity(), picturePath),
                    doctor_card_2.getWidth(), doctor_card_2.getHeight());
            if (bitmap != null) {
                doctor_card_2.setBackgroundDrawable(ImageUtils.resizePhoto(getActivity(), picturePath));
                doctor_card_2.setImageBitmap(null);
                photoPopupWindow.dismiss();
            }
        }
        break;
    default:
        break;
    }
}

From source file:com.logilite.vision.camera.CameraLauncher.java

/**
 * Applies all needed transformation to the image received from the gallery.
 *
 * @param destType          In which form should we return the image
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 *//*from  w ww.jav  a 2s.  co m*/
private void processResultFromGallery(int destType, Intent intent) {
    Uri uri = intent.getData();
    int rotate = 0;

    // If you ask for video or all media type you will automatically get back a file URI
    // and there will be no attempt to resize any returned data
    if (this.mediaType != PICTURE) {
        this.callbackContext.success(uri.toString());
    } else {
        // This is a special case to just return the path as no scaling,
        // rotating, nor compressing needs to be done
        if (this.targetHeight == -1 && this.targetWidth == -1
                && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
            this.callbackContext.success(uri.toString());
        } else {
            String uriString = uri.toString();
            // Get the path to the image. Makes loading so much easier.
            String mimeType = FileHelper.getMimeType(uriString, this.cordova);
            // If we don't have a valid image so quit.
            Bitmap bitmap = null;
            try {
                bitmap = getScaledBitmap(uriString);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (bitmap == null) {
                Log.d(LOG_TAG, "I either have a null image path or bitmap");
                this.failPicture("Unable to create bitmap!");
                return;
            }

            if (this.correctOrientation) {
                rotate = getImageOrientation(uri);
                if (rotate != 0) {
                    Matrix matrix = new Matrix();
                    matrix.setRotate(rotate);
                    try {
                        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                                matrix, true);
                        this.orientationCorrected = true;
                    } catch (OutOfMemoryError oom) {
                        this.orientationCorrected = false;
                    }
                }
            }

            // If sending base64 image back
            if (destType == DATA_URL) {
                this.processPicture(bitmap);
            }

            // If sending filename back
            else if (destType == FILE_URI || destType == NATIVE_URI) {
                // Did we modify the image?
                if ((this.targetHeight > 0 && this.targetWidth > 0)
                        || (this.correctOrientation && this.orientationCorrected)) {
                    try {
                        String modifiedPath = this.ouputModifiedBitmap(bitmap, uri);
                        // The modified image is cached by the app in order to get around this and not have to delete you
                        // application cache I'm adding the current system time to the end of the file url.
                        this.callbackContext
                                .success("file://" + modifiedPath + "?" + System.currentTimeMillis());
                    } catch (Exception e) {
                        e.printStackTrace();
                        this.failPicture("Error retrieving image.");
                    }
                } else {
                    this.callbackContext.success(uri.toString());
                }
            }
            if (bitmap != null) {
                bitmap.recycle();
                bitmap = null;
            }
            System.gc();
        }
    }
}

From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (debug)//  w  w  w.  ja v  a  2  s .  co  m
        Log.w(TAG,
                "onActivityResult() requestCode: " + requestCode + ", resultCode: " + resultCode + ", uri: "
                        + (data == null ? "" : data.getData()) + ", data: "
                        + (data == null ? "" : MessengerApp.toString(data.getExtras())));

    if (resultCode != Activity.RESULT_OK)
        return;

    final LayerClient layerClient = ((MessengerApp) getApplication()).getLayerClient();

    switch (requestCode) {
    case REQUEST_CODE_CAMERA:

        if (photoFile == null) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but output is undefined... ");
            return;
        }
        if (!photoFile.exists()) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but photo file doesn't exist: "
                        + photoFile.getPath());
            return;
        }
        if (photoFile.length() == 0) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but photo file is empty: " + photoFile.getPath());
            return;
        }

        try {
            // prepare original
            final File originalFile = photoFile;
            FileInputStream fisOriginal = new FileInputStream(originalFile) {
                public void close() throws IOException {
                    super.close();
                    boolean deleted = originalFile.delete();
                    if (debug)
                        Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: "
                                + originalFile.getName());
                    photoFile = null;
                }
            };
            final MessagePart originalPart = layerClient.newMessagePart(Atlas.MIME_TYPE_IMAGE_JPEG, fisOriginal,
                    originalFile.length());
            File tempDir = getCacheDir();

            MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir);
            if (previewAndSize == null) {
                Log.e(TAG, "onActivityResult() cannot build preview, cancel send...");
                return;
            }
            Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]);
            if (debug)
                Log.w(TAG, "onActivityResult() sending photo... ");
            preparePushMetadata(msg);
            conv.send(msg);
        } catch (Exception e) {
            Log.e(TAG, "onActivityResult() cannot insert photo" + e);
        }
        break;
    case REQUEST_CODE_GALLERY:
        if (data == null) {
            if (debug)
                Log.w(TAG, "onActivityResult() insert from gallery: no data... :( ");
            return;
        }
        // first check media gallery
        Uri selectedImageUri = data.getData();
        // TODO: Mi4 requires READ_EXTERNAL_STORAGE permission for such operation
        String selectedImagePath = getGalleryImagePath(selectedImageUri);
        String resultFileName = selectedImagePath;
        if (selectedImagePath != null) {
            if (debug)
                Log.w(TAG, "onActivityResult() image from gallery selected: " + selectedImagePath);
        } else if (selectedImageUri.getPath() != null) {
            if (debug)
                Log.w(TAG,
                        "onActivityResult() image from file picker appears... " + selectedImageUri.getPath());
            resultFileName = selectedImageUri.getPath();
        }

        if (resultFileName != null) {
            String mimeType = Atlas.MIME_TYPE_IMAGE_JPEG;
            if (resultFileName.endsWith(".png"))
                mimeType = Atlas.MIME_TYPE_IMAGE_PNG;
            if (resultFileName.endsWith(".gif"))
                mimeType = Atlas.MIME_TYPE_IMAGE_GIF;

            // test file copy locally
            try {
                // create message and upload content
                InputStream fis = null;
                File fileToUpload = new File(resultFileName);
                if (fileToUpload.exists()) {
                    fis = new FileInputStream(fileToUpload);
                } else {
                    if (debug)
                        Log.w(TAG, "onActivityResult() file to upload doesn't exist, path: " + resultFileName
                                + ", trying ContentResolver");
                    fis = getContentResolver().openInputStream(data.getData());
                    if (fis == null) {
                        if (debug)
                            Log.w(TAG, "onActivityResult() cannot open stream with ContentResolver, uri: "
                                    + data.getData());
                    }
                }

                String fileName = "galleryFile" + System.currentTimeMillis() + ".jpg";
                final File originalFile = new File(
                        getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName);

                OutputStream fos = new FileOutputStream(originalFile);
                int totalBytes = Tools.streamCopyAndClose(fis, fos);

                if (debug)
                    Log.w(TAG,
                            "onActivityResult() copied " + totalBytes + " to file: " + originalFile.getName());

                FileInputStream fisOriginal = new FileInputStream(originalFile) {
                    public void close() throws IOException {
                        super.close();
                        boolean deleted = originalFile.delete();
                        if (debug)
                            Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: "
                                    + originalFile.getName());
                    }
                };
                final MessagePart originalPart = layerClient.newMessagePart(mimeType, fisOriginal,
                        originalFile.length());
                File tempDir = getCacheDir();

                MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir);
                if (previewAndSize == null) {
                    Log.e(TAG, "onActivityResult() cannot build preview, cancel send...");
                    return;
                }
                Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]);
                if (debug)
                    Log.w(TAG, "onActivityResult() uploaded " + originalFile.length() + " bytes");
                preparePushMetadata(msg);
                conv.send(msg);
            } catch (Exception e) {
                Log.e(TAG, "onActivityResult() cannot upload file: " + resultFileName, e);
                return;
            }
        }
        break;

    default:
        break;
    }
}

From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java

private void returnImageToProcess(Bitmap bitmap, int srcType, int destType, Intent intent, int rotate) {
    Uri uri = intent.getData();

    if (destType == DATA_URL) {
        processPicture(bitmap);//from w  ww  .java2  s .  c o m
    }

    // If sending filename back
    else if (destType == FILE_URI || destType == NATIVE_URI) {
        // Do we need to scale the returned file
        if (targetHeight > 0 && targetWidth > 0) {
            try {
                // Create an ExifHelper to save the exif data that is lost during compression
                String resizePath = getTempDirectoryPath() + "/resize.jpg";
                // Some content: URIs do not map to file paths (e.g. picasa).
                String realPath = FileHelper.getRealPath(uri, cordova);
                ExifHelper exif = new ExifHelper();
                if (realPath != null && encodingType == JPEG) {
                    try {
                        exif.createInFile(realPath);
                        exif.readExifData();
                        rotate = exif.getOrientation();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                OutputStream os = new FileOutputStream(resizePath);
                bitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os);
                os.close();

                // Restore exif data to file
                if (realPath != null && encodingType == JPEG) {
                    exif.createOutFile(resizePath);
                    exif.writeExifData();
                }

                // The resized image is cached by the app in order to get around this and not have to delete you
                // application cache I'm adding the current system time to the end of the file url.
                callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());
            } catch (Exception e) {
                e.printStackTrace();
                failPicture("Error retrieving image.");
            }
        } else {
            callbackContext.success(uri.toString());
        }
    }
    if (bitmap != null) {
        bitmap.recycle();
        bitmap = null;
    }
    System.gc();
}

From source file:bolts.AppLinkTest.java

public void testSimpleAppLinkNavigationExplicit() throws Exception {
    AppLink.Target target = new AppLink.Target(PACKAGE_NAME, "bolts.utils.BoltsActivity", Uri.parse("bolts://"),
            "Bolts");
    AppLink appLink = new AppLink(Uri.parse("http://www.example.com/path"), Arrays.asList(target),
            Uri.parse("http://www.example.com/path"));

    AppLinkNavigation.NavigationResult navigationType = AppLinkNavigation.navigate(activityInterceptor,
            appLink);//from w w  w.  jav  a2 s.  c  o  m

    assertEquals(AppLinkNavigation.NavigationResult.APP, navigationType);
    assertEquals(1, openedIntents.size());

    Intent openedIntent = openedIntents.get(0);
    assertEquals(Uri.parse("http://www.example.com/path"), AppLinks.getTargetUrl(openedIntent));
    assertEquals("bolts", openedIntent.getData().getScheme());
}

From source file:bolts.AppLinkTest.java

public void testSimpleAppLinkNavigationImplicit() throws Exception {
    // Don't provide a class name so that implicit resolution occurs.
    AppLink.Target target = new AppLink.Target(PACKAGE_NAME, null, Uri.parse("bolts://"), "Bolts");
    AppLink appLink = new AppLink(Uri.parse("http://www.example.com/path"), Arrays.asList(target),
            Uri.parse("http://www.example.com/path"));

    AppLinkNavigation.NavigationResult navigationType = AppLinkNavigation.navigate(activityInterceptor,
            appLink);/*from   ww w  . j a v a2s. c o m*/

    assertEquals(AppLinkNavigation.NavigationResult.APP, navigationType);
    assertEquals(1, openedIntents.size());

    Intent openedIntent = openedIntents.get(0);
    assertEquals(Uri.parse("http://www.example.com/path"), AppLinks.getTargetUrl(openedIntent));
    assertEquals("bolts", openedIntent.getData().getScheme());
}

From source file:bolts.AppLinkTest.java

public void testAppLinkNavigationMultipleTargetsNoFallbackImplicit() throws Exception {
    // Remove the class name to make it implicit
    AppLink.Target target = new AppLink.Target(PACKAGE_NAME, null, Uri.parse("bolts://"), "Bolts");
    AppLink.Target target2 = new AppLink.Target(PACKAGE_NAME, null, Uri.parse("bolts2://"), "Bolts 2");
    AppLink appLink = new AppLink(Uri.parse("http://www.example.com/path"), Arrays.asList(target, target2),
            Uri.parse("http://www.example.com/path"));

    AppLinkNavigation.NavigationResult navigationType = AppLinkNavigation.navigate(activityInterceptor,
            appLink);//from   w ww . jav a  2  s.  c  o  m

    assertEquals(AppLinkNavigation.NavigationResult.APP, navigationType);
    assertEquals(1, openedIntents.size());

    Intent openedIntent = openedIntents.get(0);
    assertEquals(Uri.parse("http://www.example.com/path"), AppLinks.getTargetUrl(openedIntent));
    assertEquals("bolts", openedIntent.getData().getScheme());
}

From source file:com.almalence.opencam.Fragment.java

@TargetApi(19)
@Override//from www .j  av a2 s  .  c o  m
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CHOOSE_FOLDER_CODE) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.instance);
        if (resultCode == Activity.RESULT_OK) {
            Uri treeUri = data.getData();

            getActivity().getContentResolver().takePersistableUriPermission(treeUri,
                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

            prefs.edit().putString(ApplicationScreen.sSavePathPref, treeUri.toString()).commit();
        } else {
            prefs.edit().putString(ApplicationScreen.sSaveToPref, "0").commit();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:bolts.AppLinkTest.java

public void testAppLinkNavigationMultipleTargetsNoFallbackExplicit() throws Exception {
    AppLink.Target target = new AppLink.Target(PACKAGE_NAME, "bolts.utils.BoltsActivity", Uri.parse("bolts://"),
            "Bolts");
    AppLink.Target target2 = new AppLink.Target(PACKAGE_NAME, "bolts.utils.BoltsActivity2",
            Uri.parse("bolts2://"), "Bolts 2");
    AppLink appLink = new AppLink(Uri.parse("http://www.example.com/path"), Arrays.asList(target, target2),
            Uri.parse("http://www.example.com/path"));

    AppLinkNavigation.NavigationResult navigationType = AppLinkNavigation.navigate(activityInterceptor,
            appLink);/*ww  w.  ja  va2s  .c  o  m*/

    assertEquals(AppLinkNavigation.NavigationResult.APP, navigationType);
    assertEquals(1, openedIntents.size());

    Intent openedIntent = openedIntents.get(0);
    assertEquals(Uri.parse("http://www.example.com/path"), AppLinks.getTargetUrl(openedIntent));
    assertEquals("bolts", openedIntent.getData().getScheme());
}

From source file:bolts.AppLinkTest.java

public void testAppLinkNavigationMultipleTargetsWithFallbackImplicit() throws Exception {
    // Remove the class name to make it implicit
    AppLink.Target target = new AppLink.Target(PACKAGE_NAME, null, Uri.parse("invalid://"), "Bolts");
    AppLink.Target target2 = new AppLink.Target(PACKAGE_NAME, null, Uri.parse("bolts2://"), "Bolts 2");
    AppLink appLink = new AppLink(Uri.parse("http://www.example.com/path"), Arrays.asList(target, target2),
            Uri.parse("http://www.example.com/path"));

    AppLinkNavigation.NavigationResult navigationType = AppLinkNavigation.navigate(activityInterceptor,
            appLink);/*from   w  w  w.ja va  2s .co m*/

    assertEquals(AppLinkNavigation.NavigationResult.APP, navigationType);
    assertEquals(1, openedIntents.size());

    Intent openedIntent = openedIntents.get(0);
    assertEquals(Uri.parse("http://www.example.com/path"), AppLinks.getTargetUrl(openedIntent));
    assertEquals("bolts2", openedIntent.getData().getScheme());
}