I got it using this code
ActivityManager am = (ActivityManager) mContext
.getSystemService(Activity.ACTIVITY_SERVICE);
String packageName = am.getRunningTasks(1).get(0).topActivity
.getPackageName();
Question
I am developing an custom keyboard/Input method service as given bellow
http://android-developers.blogspot.in/2009/04/creating-input-method.html
In this I want to know which client application is using my keyboard? Like user is typing a message with my keyboard or writing an email or any other app like whatsapp..
Is there any way? Please help
Solution
I got it using this code
ActivityManager am = (ActivityManager) mContext
.getSystemService(Activity.ACTIVITY_SERVICE);
String packageName = am.getRunningTasks(1).get(0).topActivity
.getPackageName();