handle Image Capture Result - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

handle Image Capture Result

Demo Code

import java.io.File;
import java.io.FileNotFoundException;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

public class Main {

  public static final boolean HAS_IMAGE_CAPTURE_BUG = true;
  private static final String TAG = "";
  private static final String TMP_SD_LOCATION_JPG = "abc.jpg";


  public static Uri handleImageCaptureResult(Context context, Intent intent) {
    Uri u;//from   w w  w  .j  a  v a  2 s  . c o m
    if (HAS_IMAGE_CAPTURE_BUG) {
      final File fi = new File(TMP_SD_LOCATION_JPG);
      try {
        u = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(context.getContentResolver(),
            fi.getAbsolutePath(), null, null));
        if (!fi.delete()) {
          Log.i(TAG, "Failed to delete " + fi);
        }
      } catch (final FileNotFoundException e) {
        u = null;
        e.printStackTrace();
      }
    } else {
      u = intent.getData();
    }
    return u;
  }
    private static boolean hasImageCaptureBug() {
        final ArrayList<String> devices = new ArrayList<String>();
        // list of known devices that have the bug

        devices.add("android-devphone1/dream_devphone/dream");
        devices.add("generic/sdk/generic");
        devices.add("vodafone/vfpioneer/sapphire");
        devices.add("tmobile/kila/dream");
        devices.add("verizon/voles/sholes");
        devices.add("google_ion/google_ion/sapphire");

        final String devstring = android.os.Build.BRAND + "/"
                + android.os.Build.PRODUCT + "/" + android.os.Build.DEVICE;
        Log.d(TAG, "device string: " + devstring);
        return devices.contains(devstring);
    }
}

Related Tutorials