content: package com.alextam.uploadimage;
  
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Environment;
  import android.provider.MediaStore;
  import android.text.TextUtils;
  import android.util.Log;
  
  import java.io.File;
  
  
  public class ImageUtil {
  
      private static final String TAG ="ImageUtil";
  
  
      /**
       * go for Album.
       */
      public static final Intent choosePicture() {
          Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
          intent.setType("image/*");
          return Intent.createChooser(intent, null);
      }
  
      /**
       * go for camera.
       */
      public static final Intent takeBigPicture() {
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, newPictureUri(getNewPhotoPath()));
          return intent;
      }
  
      public static final String getDirPath() {
          return Environment.getExternalStorageDirectory().getPath() + "/UploadImage";
      }
  
      private static final String getNewPhotoPath() {
          return getDirPath() + "/" + System.currentTimeMillis() + ".jpg";
      }
  
      public static final String retrievePath(Context context, Intent sourceIntent, Intent dataIntent) {
          String picPath = null;
          try {
              Uri uri;
              if (dataIntent != null) {
                  uri = dataIntent.getData();
                  if (uri != null) {
                      picPath = ContentUtil.getPath(context, uri);
                  }
                  if (isFileExists(picPath)) {
                      return picPath;
                  }
  
                  Log.w(TAG, String.format("retrievePath failed from dataIntent:%s, extras:%s", dataIntent, dataIntent.getExtras()));
              }
  
              if (sourceIntent != null) {
                  uri = sourceIntent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
                  if (uri != null) {
                      String scheme = uri.getScheme();
                      if (scheme != null && scheme.startsWith("file")) {
                          picPath = uri.getPath();
                      }
                  }
                  if (!TextUtils.isEmpty(picPath)) {
                      File file = new File(picPath);
                      if (!file.exists() || !file.isFile()) {
                          Log.w(TAG, String.format("retrievePath file not found from sourceIntent path:%s", picPath));
                      }
                  }
              }
              return picPath;
          } finally {
              Log.d(TAG, "retrievePath(" + sourceIntent + "," + dataIntent + ") ret: " + picPath);
          }
      }
  
      private static final Uri newPictureUri(String path) {
          return Uri.fromFile(new File(path));
      }
  
      private static final boolean isFileExists(String path) {
          if (TextUtils.isEmpty(path)) {
              return false;
          }
          File f = new File(path);
          if (!f.exists()) {
              return false;
          }
          return true;
      }
  }
  