Wednesday, December 19, 2012

Filter logcat Output by Tag Names

When debugging on android development, sometimes it is hard to find what we need when there are too much data displays on logcat. Most of the time when I do debugging on android, I use the terminal. It's pretty fast and I find it more comfortable than the logcat from Eclipse android plugin. Sometimes I missed out important data because there are unnecessary information displayed on logcat. So what I do is to save the logcat into a file and check it into a browser. This is time consuming though you have all the information. One way to sort out this problem is to filter logcat. adb logcat command has the option to filter your tags that you define in your application. In your code, you might have something similar like this:
private static final String TAG = "Fragment01";
Log.d(TAG, "getUserVisibleHint=" + getUserVisibleHint());
To display "Fragment01" in logcat,
$ adb logcat -s "Fragment01"
But this information isn't enough. What if you also need to see the values of fragment 2? or fragment 3? and etc.? Run this command.
$ adb logcat -s "Fragment01" "Fragment02" "Fragment03"
By adding the tag names on the command this will allow adb to filter it and display in logcat. Do you have some ideas similar to this? Glad if you could share. Let me know your thoughts.

Friday, September 21, 2012

USB Debugging on Samsung Galaxy Tab Using Ubuntu

If you are developing android applications using either the Samsung Galaxy Tab 7" or the 10.1", chances are you'll have a hard time using adb to these devices.  If you have followed these instructions in the android developer site and you find it working for you, then congratulations!  In my case, it's different.  Restarting the udev and adb doesn't work for me.  When I try the command adb devices, it shows,

$ adb devices
List of devices attached
????????????    device

and if I check the devices attached to my machine using lsusb it shows,

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 0a5c:21bc Broadcom Corp. BCM2070 Bluetooth 2.1 + EDR
Bus 001 Device 005: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II]

Samsung handles these attached devices differently.  I'm still not sure what causes this but it has something to do with the MTP (Mobile Transfer Protocol).  So what I did, I googled for answers and found this answer from stack exchange.  Thanks to this guy a.k.a Flow.  I guess this may work for you.  So go ahead and check his answer and don't forget to upvote it.

Tuesday, September 4, 2012

Is Unity3D Supported On Your Ubuntu?

One way to check if Unity3D is supported in your Ubuntu, open a terminal and type this command

$ /usr/lib/nux/unity_support_test -p

Result should tell if Unity3D is supported like the image below.

Do you have any tips on how to tell if you're on Unity3D?  Glad if you share.

Wednesday, August 29, 2012

ActionBarSherlock and ViewPagerIndicator Pattern for Pre-HoneyComb Devices

Download the libraries:

Extract the zip files.  These libraries are packaged with sample codes.  Import these libraries into your Eclipse projects.

Create your new project.  I assume that you are an Eclipse user and not new to android development.  Add these libraries to your project as a library project.  By adding these libraries to your new project, you are telling Android that you are using ActionBarSherlock and ViewPagerIndicator as part of your android project.

To check if libraries are added, go to Project Properties > Android.  It should look like this:

If you encountered an error like this, it's okay don't panic.
This tells that Eclipse detected android-support-v4.jar file in the dependecy list of your project twice but with different SHA-1 hash.  To fix this, just remove the file under <your_projectname>/libs/android-support-v4.jar

Now let's proceed to the fun part... the code.

layout xml.

package com.zipcerio.vpi;

import java.util.ArrayList;
import java.util.List;

import com.actionbarsherlock.view.Menu;
import com.viewpagerindicator.TitlePageIndicator;

import android.os.Bundle;

public class MainActivity extends SherlockFragmentActivity {
 private ViewPager mPager;
 private TitlePageIndicator mIndicator;
 private MainPagerAdapter mAdapter;
 private List mFragments;
 private static final String FRAGMENT1 = Fragment1.class.getName();
 private static final String FRAGMENT2 = Fragment1.class.getName();
 private static final String FRAGMENT3 = Fragment1.class.getName();

 public void onCreate(Bundle savedInstanceState) {
  // add fragments
  mFragments = new ArrayList();
  mFragments.add(Fragment.instantiate(this, FRAGMENT1));
  mFragments.add(Fragment.instantiate(this, FRAGMENT2));
  mFragments.add(Fragment.instantiate(this, FRAGMENT3));
  // adapter
  mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);
  // pager
  mPager = (ViewPager) findViewById(;
  // indicator
  mIndicator = (TitlePageIndicator) findViewById(;

 public boolean onCreateOptionsMenu(Menu menu) {
  return true;
package com.zipcerio.vpi;

import java.util.List;


public class MainPagerAdapter extends FragmentPagerAdapter {
 private List mFragments;
 private String[] titles = new String[] {"FRAGMENT1", "FRAGMENT2", "FRAGMENT3"};
 private int mCount = titles.length;

 public MainPagerAdapter(FragmentManager fm, List f) {
  mFragments = f;

 public Fragment getItem(int position) {
  return mFragments.get(position);

 public int getCount() {
  return mCount;

 public CharSequence getPageTitle(int position) {
  return titles[position];
package com.zipcerio.vpi;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class Fragment1 extends SherlockFragment {
 private ListView mList;

 public View onCreateView(LayoutInflater inf, ViewGroup grp, Bundle icicle) {
  View v = inf.inflate(R.layout.f_fragment1, grp, false);
  mList = (ListView) v.findViewById(;
  return v;

 public void onActivityCreated(Bundle savedInstanceState) {
  ArrayAdapter adapter = new ArrayAdapter(
    getActivity(), android.R.layout.simple_list_item_1, Cheese.STRINGS);


AndroidManifest file




Finally, this is how it should look like.

See the source code here.

Credit goes to Jake Wharton for these great libraries.

Check CPU Information and Speed

To check CPU information and speed on your Ubuntu or any Linux distro, open the terminal and run this command:

$ cat /proc/cpuinfo

If you have other techniques and ways, please feel free to add it in the comments.

Friday, August 10, 2012

Multiple Workspaces in Eclipse

If you're on the point where all your projects are flooded on your Eclipse package explorer, chances are very difficult to find other library projects when working on a project that references those projects. One way to organize your Eclipse projects is to switch workspaces.  To switch workspaces, go to Eclipse > File > Switch Workspace.

This is a great solution but you will loose all your settings.  Settings like keybindings, code formats, and custom templates are gone.  To set the settings to your new workspace, just copy the folder from your old workspace to your new workspace.

$ cp {old_workspace}/.metadata/.plugins/.org.eclipse.core.runtime/.settings {new_workspace}/

Restart Eclipse.

Monday, July 30, 2012

Google App Engine

Google App Engine (GAE) lets you run web applications on Google infrastructure.  The good thing in this technology is that there's no need for you to maintain the server.  You can also use this technology as backend to your android applications (it means that this provides the data exchange between your android application, application server, and GCM).  You can run Java, Go, and Python environments for your web application environment.  This article will tackle Java and Android stuffs.  More of this stuff can be found here.

To send/receive JSON data for an Android application.
In this article, I use Eclipse on Ubuntu for the development.


Download the Google App Engine SDK for Java here.

In Eclipse, go to Help > Install New Software > Work With textbox, get the Eclipse update site url here.

Right after the installation, Google plugin is added in the Eclipse toolbar.

Now you can

Creating and Running a Web Application

To create a sample web application, click on the Google plugin then select 'New Web Application Project' and click 'Finish'. A sample Hello World code is provided in your new web application project.  To Run, hit on Run button, Run As > Web Application.  Check and see your browser.  Your web application project is hosted locally.  The url is http://localhost:8888.

Then deploy this project in GAE.  To deploy, click the Google plugin and click Deploy To App Engine > App Engine Project Settings > enter your ProjectId in the Application ID textbox > hit OK > Deploy

Once deployment is successful, you can see something like this image below.

Save logcat to a File

To save a logcat into a file, simply open the terminal and run this command

$ adb logcat -d > filename.txt

where filename.txt is any name you want.

Saturday, June 16, 2012

ADB Over Wifi

When you are doing android development and you don't have the usb adapter with you, there's a way to use adb by tweaking your device using adb over wifi.  To do this, your device must be rooted. I'm using CyanogenMod and this tweak is part of the features.  First, enable the ADB Over Wifi then restart the device.

Once restarted go to your Terminal Emulator.
$ su
# setprop service.adb.tcp.port 5555
# stop adbd
# start adbd

On your computer, 
$ adb connect

The ip address on the example is the ip address of your device. If you don't know how to get the ip address of your device, here's a quick step.  Go to Settings > Wireless & Networks > Wifi Settings > select the network that you're connected to.

And you should be connected!  Now you can proceed with android development without worrying your usb adapter.

More detailed info here.

Wednesday, June 13, 2012

Setting Android Environment Variable

When debugging android applications, I always use the terminal to check the logcat but using it I still have to go to tools directory under android sdk.  It's very inconvenient for me since I cannot use the android commands in other directories.  By default, setting up the android sdk into Eclipse for the first time, ANDROID_HOME environment variable isn't setup by linux file system.  To setup,

open the terminal and edit the .bashrc file and add these lines at the end of the file:

and then append this to the current PATH
export PATH

The tools and platform-tools directory are the most important here since they contain all the android-related commands.

Sunday, June 10, 2012

Add Workspaces in Unity 2D

In Lucid Lynx, I am used to work with 6 workspaces and each workspace has its own function.  One workspace for Chrome, one for Eclipse, one for the Terminal (logcat), one for the Android Emulator, and the other one for Pidgin.  I am an LTS user and I wasn't bothered by other releases (Maverick Meerkat, Natty Narwhal, Oneiric Ocelot) until when Precise Pangolin was released, the desktop was changed from GNOME to Unity interface.  Now I upgraded my Lynx to the new LTS Pangolin on both my desktop and laptop.

I experienced different issues on desktop and on my laptop with the Unity interface.  The first look into Unity from desktop and laptop puzzled me.  On desktop, I can change the size of the launcher to 32 and add more workspaces in it.  Glad I found MyUnity, a tweaking tool for Unity desktop.  On laptop, I see no options to change the launcher size.  MyUnity only works on Unity 3D.  Now this made me think that my laptop has Unity 2D.  Then I did my research and found this tweak.

On terminal:
$ wget
$ chmod +x
$ sudo ./ 32

The '32' changes your icon launcher size to minimum.  Now to add more workspaces to your Unity desktop, I also found this tweak.

On terminal, you have change thru gconf and run this command:
$ gconftool-2 -s -t integer /apps/metacity/general/num_workspaces 6

Restart your machine.

Do you have any alternatives?  Glad if you share.  Just add it in the comments.

Tuesday, May 22, 2012

Setup Multiple Devices for Android Development

I didn't find good resources in setting up multiple devices for android development.  When using Windows, if devices are plugged in via usb, it automatically installs the driver.  In Linux, it's different.  You have to do it manually.  Good example is in Android Developer page but this doesn't answer my problem. I have my LG device and 2 of our test devices at work (HTC and Samsung Galaxy Tab).  So I have to test it myself and here's what I did.

Go to rules.d directory
$ home_dir/etc/udev/rules.d

Create a file for each device
$ vim 51-android.rules
$ vim 61-android.rules
$ vim 71-android.rules

On the content, change the ATTR{idVendor} to specific USB Vendor IDs
For LG
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666", GROUP="plugdev"

Lastly, change the file permission
chmod a+r /etc/udev/rules.d/51-android.rules

Restart udev
$ sudo restart udev

To check, use adb command.
android_sdk_dir$ ./adb devices
List of devices attached 
emulator-5554     device
HT115HL12346     device
46411929E53773CE    device
It should display the list of devices...

Do you have any other methods? Put it on the comments.

Tuesday, April 17, 2012

Hello World!

Toast.makeText(context, "Hello World", Toast.LENGTH_LONG).show();