Wednesday, June 20, 2012

android::CameraHardwareSec::takePicture() : capture already in progress error

Today, One of the Android devices keep getting crashed while taking a picture in a TimerTask. I was keep getting this error

E/CameraHardwareSec(75): virtual android::status_t android::CameraHardwareSec::takePicture() : capture already in progress
E/PanicImageActivity(1750): java.lang.RuntimeException: takePicture failed

problem is before you call this method again in the TimerTask run method. you need to make sure that there is one not in progress. Some devices cameras are very slow on processing picture frames.

private final Semaphore mutex = new Semaphore(1);

try {


mCamera.takePicture(null, null, new PictureCallback() { 
        public void onPictureTaken(byte[] data, Camera camera) {
try {
             // Do something here

         catch(Throwable t) {

catch (Throwable t) {


Tuesday, June 19, 2012

How to check whether Android Media Scanner is running ?

Here is the code

    public static final boolean isMediaScannerScanning(final ContentResolver cr) {
        boolean result = false;
        final Cursor cursor = query(cr, MediaStore.getMediaScannerUri(), new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null,
                null, null);
        if (cursor != null) {
            if (cursor.getCount() == 1) {
                result = "external".equals(cursor.getString(0));
        return result;

How to open a local file in Android browser?

Important thing here is you have to use file:// + path

 private String genLocalPageUrl(String fileName)  {
    return "file://" + this.getFilesDir() + "/" +  fileName ;

How to open browser link in new tab or not open in Android?

This is not something I was not looking for but I just found it. I thought it will be helpful for someone out there.

key point here is putExtra("create_new_tab", false);

Intent  intent  = new Intent("android.intent.action.VIEW", null);
intent.putExtra("create_new_tab", false); // true or false
intent.putExtra("", paramComponentName.getPackageName());