From 69d6bfb51a4a579dfb52ff1b79e20f0d26ccc334 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Tue, 28 Feb 2012 21:42:55 -0800 Subject: [PATCH] Only show option to take a picture if you have a camera --- .../astrid/actfm/ActFmCameraModule.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java index 33633dc5c..069c0e6a7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java @@ -8,6 +8,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -74,12 +75,17 @@ public class ActFmCameraModule { public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) { ArrayList options = new ArrayList(); - options.add(fragment.getString(R.string.actfm_picture_camera)); + + final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + PackageManager pm = fragment.getActivity().getPackageManager(); + if(pm.queryIntentActivities(cameraIntent, 0).size() > 0) + options.add(fragment.getString(R.string.actfm_picture_camera)); + options.add(fragment.getString(R.string.actfm_picture_gallery)); - if (clearImageOption != null) { + if (clearImageOption != null) options.add(fragment.getString(R.string.actfm_picture_clear)); - } + ArrayAdapter adapter = new ArrayAdapter(fragment.getActivity(), android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); @@ -89,11 +95,9 @@ public class ActFmCameraModule { public void onClick(DialogInterface d, int which) { if(which == 0) { lastTempFile = getTempFile(fragment.getActivity()); - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - if (lastTempFile != null) { - intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); - } - fragment.startActivityForResult(intent, REQUEST_CODE_CAMERA); + if (lastTempFile != null) + cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); + fragment.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } else if (which == 1) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*");