I am looking for a solution that i would like to get user opened or installed application on his device.I have to get which app opened by user from my BroadcastReceiver class.I have implemented my code as follows:
public class AppReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
ActivityManager am = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = context.getPackageManager();
while(i.hasNext()) {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try {
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
Log.v(" App Name : ", c.toString());
}catch(Exception e) {
}
}
}
I have also added about this reciever on manifest file as :
<receiver android:name="AppReciever">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_CHANGED"></action>
<action android:name="android.intent.action.PACKAGE_INSTALL"></action>
<action android:name="android.intent.action.PACKAGE_REPLACED"></action>
<action android:name="android.intent.action.PACKAGE_RESTARTED"></action>
<data android:scheme="package" />
</intent-filter>
</receiver>
From the above code AppReciver not executing for get the app name at Log.v when I opened new app which are already existed(installed) on the device.It is working for only once other app run on device.
Please any body help me on get the current opened applications from BroadcastReceiver