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
Add to you service registerReceiver(). Don't forget to unregister receiver;
AppReceiver appReceiver = new AppReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.setPriority(900);
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL); //@deprecated This constant has never been used.
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
registerReceiver(appReceiver, intentFilter);
For unregistering: unregisterReceiver(appReceiver);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With