Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>this is a <a href="http://code.google.com/p/android/issues/detail?id=1480" rel="noreferrer">well documented bug</a> in some versions of android. that is, on google experience builds of android, image capture doesn't work as documented. what i've generally used is something like this in a utilities class.</p> <pre><code>public boolean hasImageCaptureBug() { // list of known devices that have the bug ArrayList&lt;String&gt; devices = new ArrayList&lt;String&gt;(); 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"); return devices.contains(android.os.Build.BRAND + "/" + android.os.Build.PRODUCT + "/" + android.os.Build.DEVICE); } </code></pre> <p>then when i launch image capture, i create an intent that checks for the bug.</p> <pre><code>Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); if (hasImageCaptureBug()) { i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("/sdcard/tmp"))); } else { i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } startActivityForResult(i, mRequestCode); </code></pre> <p>then in activity that i return to, i do different things based on the device.</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case GlobalConstants.IMAGE_CAPTURE: Uri u; if (hasImageCaptureBug()) { File fi = new File("/sdcard/tmp"); try { u = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), fi.getAbsolutePath(), null, null)); if (!fi.delete()) { Log.i("logMarker", "Failed to delete " + fi); } } catch (FileNotFoundException e) { e.printStackTrace(); } } else { u = intent.getData(); } } </code></pre> <p>this saves you having to write a new camera app, but this code isn't great either. the big problems are</p> <ol> <li><p>you never get full sized images from the devices with the bug. you get pictures that are 512px wide that are inserted into the image content provider. on devices without the bug, everything works as document, you get a big normal picture.</p></li> <li><p>you have to maintain the list. as written, it is possible for devices to be flashed with a version of android (say <a href="http://www.cyanogenmod.com/" rel="noreferrer">cyanogenmod's builds</a>) that has the bug fixed. if that happens, your code will crash. the fix is to use the entire device fingerprint.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload