I am working with custom keyboard ,I need current package name when keyboard is open . This keyboard will be open with different different application ,so i need that application package name which is open currently. I am using following code but its not working properly.
ActivityManager mActivityManager = (ActivityManager)PhotoActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
if(Build.VERSION.SDK_INT > 20){
String mPackageName = mActivityManager.getRunningAppProcesses().get(0).processName;
Log.e("Checking package: ","Checking current application package"+mPackageName);
}
else{
String mPackageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
}