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("com.android.mms.util.ContactInfoCache", true, c)
.getMethod("init", Context.class).invoke(null, context);
Class.forName("com.android.mms.transaction.MessagingNotification", true, c)
.getMethod("updateAllNotifications", Context.class).invoke(null, context);
This piece of code will trigger Android new message arrival notification. Interesting ...
Monday, August 22, 2011
How call a method/function inside a APK file in Android?
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.
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!
Eg.
registerContentObserver(uri, true, observer);
notifyForDescendents parameter as true. Weird but it worked!
Eg.
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.
@Override
public void onCreate(){
super.onCreate();
registerReceiver(
new ThikReceiver(),
new IntentFilter(Intent.ACTION_TIME_TICK));
}
}
public class ThikReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0)
// Do something
else
// Do something else
}
}
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.
@Override
public void onCreate(){
super.onCreate();
registerReceiver(
new ThikReceiver(),
new IntentFilter(Intent.ACTION_TIME_TICK));
}
}
public class ThikReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0)
// Do something
else
// Do something else
}
}
Friday, July 29, 2011
How to create a thread in android without hurting the UI
Sometimes when we want to do something out of the ordinary like pushing something to the server while user is playing a game or checking emails we create Threads. If you do not set the thread priority to low this might hurt the UI performance.
Correct way to do is to call setPriority in the thread class.
SomeTaskThread someTaskThread = new SomeTaskThread();
someTaskThread.setPriority(Thread.NORM_PRIORITY-1); //Make the background thread low priority. This way it will not affect the UI performance
someTaskThread.start();
or you can use AsyncTask class.
Correct way to do is to call setPriority in the thread class.
SomeTaskThread someTaskThread = new SomeTaskThread();
someTaskThread.setPriority(Thread.NORM_PRIORITY-1); //Make the background thread low priority. This way it will not affect the UI performance
someTaskThread.start();
or you can use AsyncTask class.
Monday, July 18, 2011
Unable to find instrumentation target package ? duh!
Today I was trying to write some test cases after i got inspired by this link
Problem was I was keep getting "Unable to find instrumentation target package" Error and not sure how to fix it. Well there are few ways to fix this problem. Easy way out is:
1.Double click on the AndroidManifest.xml
Delete any "instrumentation" tags
2.Goto Instrumentation Tab
3.Click Add
4.Select Instrumentation
5. Select the name and target package.
This should work. Trying to add the Instrumentation manually is a nightmare.
Hope this will help to someone else
Problem was I was keep getting "Unable to find instrumentation target package" Error and not sure how to fix it. Well there are few ways to fix this problem. Easy way out is:
1.Double click on the AndroidManifest.xml
Delete any "instrumentation" tags
2.Goto Instrumentation Tab
3.Click Add
4.Select Instrumentation
5. Select the name and target package.
This should work. Trying to add the Instrumentation manually is a nightmare.
Hope this will help to someone else
Sunday, July 3, 2011
How do I investigate an Application Not Responding (ANR) in Android?
Today I got an ANR error and it's really annoying because you know you have done something wrong and not sure where to look for to find out the problem.
When I googled, I found this on StackOverFlow.
"An ANR happens when some long operation takes place in the "main" thread. This is the event loop thread, and if it is busy, Android cannot process any further GUI events in the application, and thus throws up an ANR dialog." - From Stackoverflow
so, how to diagnose the problem, it's easy,
adb shell cat /data/anr/traces.txt
will drump all the appplication not responding traces to the command prompt. (Make sure to change the command prompt buffer size otherwise you can not see the full log out)
When I googled, I found this on StackOverFlow.
"An ANR happens when some long operation takes place in the "main" thread. This is the event loop thread, and if it is busy, Android cannot process any further GUI events in the application, and thus throws up an ANR dialog." - From Stackoverflow
so, how to diagnose the problem, it's easy,
adb shell cat /data/anr/traces.txt
will drump all the appplication not responding traces to the command prompt. (Make sure to change the command prompt buffer size otherwise you can not see the full log out)
Subscribe to:
Posts (Atom)