I need to get action name of intent filter located in service tags from specified installed package name. Actually, this issue may related to parsing AndroidManifest.xml file, but I want to use relevant functions/classes provided by Android to get action name instead of parsing xml directly.
Well, to put it more clearly; I am writing a code that gets installed apps and then filters media apps. When I compare manifest files of some media applications, I figured out that the common thing they use "android.media.browse.MediaBrowserService" action name. So, I thought I could create a filter by looking for this service action name.
Here is a sample snippet from AndroidManifest.xml:
...
<service
android:name="com.example.mediabrowser.XXXMediaBrowserService"
android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
...
I hope everything has been well understood so far. After realizing all this stuff, I pulled the services name from the installed package name by filtering Intent.ACTION_MAIN.
final List<PackageInfo> packages = pm.getInstalledPackages(0);
for(PackageInfo pi : packages)
{
pi = getPackageManager().getPackageInfo(pi.packageName, PackageManager.GET_SERVICES);
Log.e("SERVICES: ", pi.packageName + Arrays.toString(pi.services));
}
This code just presents me the service list. So I was able to capture the service name "com.example.mediabrowser.XXXMediaBrowserService" in the AndroidManifest.xml that I mentioned above.
My purpose is to pull the action name (android.media.browse.MediaBrowserService) that belongs to in this service. I tried a few methods on how to do this, but I couldn't get any results.
Have a nice day.
Good news!
The solution is here,
final Intent providerIntent = new Intent(MediaBrowserService.SERVICE_INTERFACE);
List<ResolveInfo> mediaApps = pm.queryIntentServices(providerIntent, 0);
for (ResolveInfo info : mediaApps) {
Log.e("MEDIA APPS: ", String.valueOf((info.serviceInfo.packageName)));
}
Best regards...