Reputation: 21
I am developing a launcher app for android and for that i need my app to get notified for the system broadcast with actions like ACTION_PACKAGE_REMOVED, ACTION_PACKAGE_CHANGED, etc that impacts the activities available for launch with the user(to be displayed by my app).
Broadcast for package installed, package removed, package updated & package disabled/enabled are working as usual but the problem is when whole of the package is disabled like through Titanium backup or some similar app its get notified to my Broadcast receiver through system broadcast invoked having action Intent.ACTION_PACKAGE_CHANGED but when an app component like an activity is disabled individually from apps like MyAndroidTools it does not get notified to my Broadcast receiver i.e no broadcast(broadcast with Intent.ACTION_PACKAGE_CHANGED) is received from the system to my app due to disabling individual app component.
Here is my Manifest declaration of Broadcast receiver with requisite intent filter:
<receiver android:name=".LauncherBroadcastReceiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Everything is working as intented but only when whole of the package is disabled or enabled but not when a single component(say activity) is disabled or enabled.
There is definately some way of doing it as i have test checked it with some other launchers i.e. when a single component is disabled it gets reflected(disappeared in app drawer) in the launcher & vice versa for enabling the component. So those launchers are receiving this info may be some listener or broadcast.
Upvotes: 0
Views: 3395
Reputation: 21
One probable solution(not ideal) for my problem is to get the list of disabled launchable activites in Activity onResume method and than update to reflect the changes.
To get the list of disabled launchable activities:
Query package manager for all launchable activities(including disabled ones)
Intent mainLaunchIntent = new Intent(Intent.ACTION_MAIN);
mainLaunchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mainLaunchIntent.addFlags(PackageManager.MATCH_DISABLED_COMPONENTS);
List<ResolveInfo> activitiesInformationList = packageManager.queryIntentActivities(mainLaunchIntent, 0);
Query package manager for only enabled launchable activities
Intent mainLaunchIntent = new Intent(Intent.ACTION_MAIN);
mainLaunchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activitiesInformationList = packageManager.queryIntentActivities(mainLaunchIntent, 0);
List(1-2) will be the list of disabled activities. I haven't tested the same since not ideal for me would like to wait for more answers but if some1 found the same helpful can use it.
Upvotes: 1
Reputation: 6683
`<receiver android:name=".LauncherBroadcastReceiver" exported="true" enabled="true">`
Upvotes: 0