Monday, August 22, 2011

How call a method/function inside a APK file in Android?

Today I came across this piece of code and thought of sharing it with others.

PathClassLoader c = new PathClassLoader("/system/app/Mms.apk", getClassLoader());
Class.forName("", true, c)
.getMethod("init", Context.class).invoke(null, context);
Class.forName("", true, c)
.getMethod("updateAllNotifications", Context.class).invoke(null, context);

This piece of code will trigger Android new message arrival notification. Interesting ...

Thursday, August 4, 2011

Type The method compareTo(Request) of type Request must override a superclass method ? haa?

We were working on Eclipse Galileo and moved to the new version Indigo but some of the projects that were working fine in Galileo started trowing this exception. Problem is in Galileo Java compiler compliance is set to JRE 1.6 but in Indigo it's set to 1.5 for some reason.

So to fix this error you need to change the compliance to 1.6 back, To do this, Go to your Window -> Preferences -> Java -> Compiler -> Set to 1.6 and set the java compiler level to 1.6 and also make sure you select JRE 1.6 to execute your program from eclipse.

Monday, August 1, 2011

Android ContentObserver not getting notify ?

Today, I ran into a problem where my content observer is not getting notify when I delete something. After hours of searching I realized, sometime you need to set the
notifyForDescendents parameter as true. Weird but it worked!


registerContentObserver(uri, true, observer);

How to use ACTION_TIME_TICK broadcast ?

Today, I was looking into how to track change notification to the camera folder in Android. While Googling for this, I came across ACTION_TIME_TICK broadcast event.

Android Doc says
public static final String ACTION_TIME_TICK
The current time has changed. Sent every minute. You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver().

Sometimes we use a backgroud timer in our application to check for something in a continues loop but I think listening to this event is much better approach, but you have to make sure it's thread safe.

How to use.

public void onCreate(){

new ThikReceiver(),
new IntentFilter(Intent.ACTION_TIME_TICK));

public class ThikReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
if(intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0)
// Do something
// Do something else