android - How to return just applications from package manager? -


can type of application determined applicationinfo object ?

by type mean, determine if widget or application.

alternatively can list of of applications not include widgets returned getpackagemanager()? below code i'm trying return applications widgets returned also:

list<applicationinfo> appinfolist = context.getpackagemanager()         .getinstalledapplications(packagemanager.get_activities); 

i don't believe can query app or without widgets. can check activityinfo.metadata field of every registered broadcast receiver. contains instance of bundle class. receivers having widget must have metadata name android.appwidget.provider in bundle.

final packagemanager pm = act.getpackagemanager();  final intent widgetintent = new intent("android.appwidget.action.appwidget_update"); final list<resolveinfo> receivers = pm.querybroadcastreceivers(widgetintent,         packagemanager.get_meta_data);  // optional part (see note below) (resolveinfo receiver : receivers) {     activityinfo info = receiver.activityinfo;     if (info.metadata != null) {         boolean haswidget = info.metadata.containskey("android.appwidget.provider");         if (haswidget) {             system.out.println(string.format("package %s has widget",                     info.packagename));         }     } } 

note: might enough query receivers responding "android.appwidget.action.appwidget_update" action without checking metadata, because receivers intended serving widget. can assume if there receiver such action, these widget. don't need for-loop then.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -