Example #1
0
  private void attachFromCamera() {

    AnalyticsManager.getInstance()
        .sendEvent(
            AnalyticsManager.CATEGORY_MESSAGES, AnalyticsManager.ACTION_ATTACH_FROM_CAMERA, mLabel);

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (cameraIntent.resolveActivity(mContext.getPackageManager()) != null) {

      File file = null;
      try {
        file = createImageFile();
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (file != null) {
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        mActivityLauncher.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA);
      }
    } else {
      // Send a toast saying there was a camera error
      if (mContext != null) {
        String message = mContext.getResources().getString(R.string.attachment_camera_error);
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
      }
    }
  }
Example #2
0
  private void chooseAttachmentFromGallery() {

    AnalyticsManager.getInstance()
        .sendEvent(
            AnalyticsManager.CATEGORY_MESSAGES, AnalyticsManager.ACTION_ATTACH_IMAGE, mLabel);

    try {
      Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
      photoPickerIntent.setType("image/*");
      mActivityLauncher.startActivityForResult(photoPickerIntent, REQUEST_CODE_IMAGE);
    } catch (ActivityNotFoundException e) {
      // Send a toast saying no picture apps
      if (mContext != null) {
        String message = mContext.getResources().getString(R.string.attachment_app_not_found);
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
      }
    }
  }