Category Archives: Android

Aaaaaargh! onPreviewFrame is not called on Android ICS

When using the Camera preview on android, there is a setPreviewCallback method to get the preview frames. (The API doc says it will do that.)

However, I never saw the callback is being called.

try {
	callbackBuffer = new byte[mCamera.getParameters().getPreviewSize().width * mCamera.getParameters().getPreviewSize().height * (ImageFormat.getBitsPerPixel(mCamera.getParameters().getPreviewFormat()) / 8)];
    mCamera.addCallbackBuffer(callbackBuffer);
    mCamera.setPreviewCallbackWithBuffer(this);
    mCamera.setPreviewDisplay(holder);
    mCamera.startPreview();
} catch (IOException e) {
    Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}

Not works.

try {
    mCamera.setPreview(@Override
	public void onPreviewFrame(byte[] data, Camera camera) {
		Log.i(TAG, "preview");
	}
    });
    mCamera.setPreviewDisplay(holder);
    mCamera.startPreview();
} catch (IOException e) {
    Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}

Nope.

I could find a bug report about it.
onPreviewFrame never called when using setPreviewCallback

It seems like a bug on Android ICS, but it’s not clear which version is fixed. My device is 4.1.2 and just not working, and there will be so many people with ICS, because the Android device manufacturers doesn’t provide the OS update for the customers.
And android OS developers are not providing any explanation or the workaround to avoid it.

Developing on Android is just a mess..

Using Intel HAXM Android x86 emulator on OSX Mavericks 10.9

After the OSX Mavericks 10.9 update, Android x86 emulator will crash or freeze on start.

I updated all the SDKs on the Android SDK Manager, but it didn’t help. After some googling, it turns out I wasn’t the only person with such defect.

Intel released the HAXM hotfix for OSX 10.9 and Windows 8.1.
Info
Download page

After installing the hotfix, still my virtual devices didn’t work.
(Also be aware that you couldn’t use VirtualBox 4.2.14 simultaneously with the emulator.)

After some testing, Android 4.x emulator works well without a problem, but only the Android 2.3.3 emulator still crashes on start.

I was using the emulators with the ‘Use Host GPU’ option(because it is recommended), but disabling that option makes the Android 2.3.3 x86 emulator work.

I’m not sure whether it’s a applicable solution for all, but if you have the same problem, give it a try.

How to add a widget on the Home screen

[2013/11/17 Updated] Widget is disabled when you move the app to the SD card.

———————

Apps have no control on adding/removing widgets on the home screen.

The reason is simple. If any app can add a widget on the home screen programmatically, the home screen can easily be a mess.

So, the user should add the widget by himself, and it is simple.

1. Open App Drawer
1. Open App Drawer
2. Go to Widget list, select the widget and hold it on until the home screen appears
2. Go to Widget list, select the widget and hold it on until the home screen appears
3. Place the widget on the home screen
3. Place the widget on the home screen

 

Alternative way to add a widget on home screen.

Add Widget
1. There are several ways to add a widget and it could be slightly different by which Home screen launcher you are using. Tap on a blank space on the home screen and hold your finger there (long press) until the menu appears. Also, there could be a ‘+’ button or press the ‘Menu’ button and select ‘Add’ menu.

 

 

Find WIdget
2. Go to the ‘Widgets’ menu and find the widget you want to add from the list. You can layout it on the home screen.

 

 

Widget done
3. Finish!