Only show option to take a picture if you have a camera

pull/14/head
Tim Su 13 years ago
parent 338e818933
commit 69d6bfb51a

@ -8,6 +8,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@ -74,12 +75,17 @@ public class ActFmCameraModule {
public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) { public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) {
ArrayList<String> options = new ArrayList<String>(); ArrayList<String> options = new ArrayList<String>();
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)); options.add(fragment.getString(R.string.actfm_picture_gallery));
if (clearImageOption != null) { if (clearImageOption != null)
options.add(fragment.getString(R.string.actfm_picture_clear)); options.add(fragment.getString(R.string.actfm_picture_clear));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(), ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(),
android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); 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) { public void onClick(DialogInterface d, int which) {
if(which == 0) { if(which == 0) {
lastTempFile = getTempFile(fragment.getActivity()); lastTempFile = getTempFile(fragment.getActivity());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (lastTempFile != null)
if (lastTempFile != null) { cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); fragment.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA);
}
fragment.startActivityForResult(intent, REQUEST_CODE_CAMERA);
} else if (which == 1) { } else if (which == 1) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*"); intent.setType("image/*");

Loading…
Cancel
Save