2
 public void startCamera() {
  Log.d("TDM_CAMERA", "Starting camera on the phone...");
  String fileName = "testphoto.jpg";
  ContentValues values = new ContentValues();
  values.put(MediaStore.Images.Media.TITLE, fileName);
  values.put(MediaStore.Images.Media.DESCRIPTION,
          "Image capture by camera");
  values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
  imageUri = getContentResolver().insert(
          MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
  intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
  startActivityForResult(intent, 1337);
}

log cat shows the error in imageUri = getContentResolver().this line

02-08 07:32:11.505: E/AndroidRuntime(2136): FATAL EXCEPTION: main
02-08 07:32:11.505: E/AndroidRuntime(2136): java.lang.UnsupportedOperationException: Unknown URI: content://media/external/images/media
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.content.ContentProviderProxy.insert(ContentProviderNative.java:420)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.content.ContentResolver.insert(ContentResolver.java:866)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at com.Ibetter.tdm.ReqEditActivity.startCamera(ReqEditActivity.java:597)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at com.Ibetter.tdm.ReqEditActivity$4.onClick(ReqEditActivity.java:107)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.view.View.performClick(View.java:4202)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.view.View$PerformClick.run(View.java:17340)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.os.Handler.handleCallback(Handler.java:725)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.os.Looper.loop(Looper.java:137)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at java.lang.reflect.Method.invokeNative(Native Method)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at java.lang.reflect.Method.invoke(Method.java:511)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-08 07:32:11.505: E/AndroidRuntime(2136):     at dalvik.system.NativeStart.main(Native Method)
02-08 07:32:13.935: I/Process(2136): Sending signal. PID: 2136 SIG: 9
02-08 07:32:14.835: E/Trace(2175): error opening trace file: No such file or directory (2)
02-08 07:32:14.835: W/Trace(2175): Unexpected value from nativeGetEnabledTags: 0
j0ntech
  • 1,158
  • 3
  • 13
  • 27
Maruthi042
  • 145
  • 1
  • 5
  • 16

1 Answers1

0

The way you set the output file is fishy.

Try like this:

public void startCamera() throws IOException {
  Log.d("TDM_CAMERA", "Starting camera on the phone...");
  File photosDir = new File(Environment.getExternalStorageDirectory(), "photos");
  if (!photosDir.isDirectory()) {
      photosDir.mkdirs();
  }
  File imageFile = File.createTempFile("testphoto", ".jpg", photosDir);
  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
  intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
  startActivityForResult(intent, 1337);
}

Also make sure that using external storage is declared in your Android manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

For more info see this page in the docs: http://developer.android.com/training/camera/photobasics.html

janos
  • 120,954
  • 29
  • 226
  • 236
  • @janos-I used your code also but after capture the image my application has stopped,the problem showing in logcat i mention before – Maruthi042 Feb 07 '13 at 13:54
  • http://pastebin.com/ji858fNR this linke having entire one @janos – Maruthi042 Feb 07 '13 at 14:10
  • Ok, so the problem now is with the URL we are passing to `Uri.fromFile`. Please try it the way I write in my answer, using `Environment.getExternalStorageDirectory()` instead of `Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)` as I suggested earlier. – janos Feb 08 '13 at 08:25
  • I have changed the code in my answer. If you update your program using the changed code, then either your program will work, or the error message in logcat will be different. Please try it, and if you still have problems paste the new error message on logcat. – janos Feb 11 '13 at 08:54
  • ya its working,thank you,is it saving in SD card only?and how to display that image on the activity page – Maruthi042 Feb 11 '13 at 09:48
  • Glad it finally works. The example saves on SD card, you can probably tweak it to use internal storage instead. For viewing the image on Android, please refer to the documentation link I included in the answer. If this answers your question, please mark this answer accepted. – janos Feb 11 '13 at 13:07