android - getPackageInfo() throws exception when called when devices starts, but not later? -


i discovered strange behaviour of method getpackageinfo() of packagemanager class.

i have app widget, relies on particular package installed. so, in onupdate() method, test if package installed:

public boolean isappinstalled(string uri) {     packagemanager pm = context.getpackagemanager();     boolean installed = false;     int flags = packagemanager.get_activities;     try {         pm.getpackageinfo(uri, flags);         installed = true;     } catch (packagemanager.namenotfoundexception e) {         installed = false;     }     return installed; } 

so, works fine of time, when onupdate() method called. however, discovered in android 4.03 falsely throw namenotfoundexception when devices rebooted, is, while booting, widgets onupdate() method called "early" seems. when widgets onupdate method called again (half hour later), correctly throws or doesnt throw exception, depending on if package installed or not. happens on android 4.03 (didnt test honeycomb), 2.2 , 2.3 works fine.

any suggestions? workaround?

the list of installed apps valid after packagemanager has finished scanning them. internally installed apps appear pretty (possibly before have time know difference), externally installed apps rely on sd card being mounted, can take long time on platforms.

unfortunately there doesn't appear useful events or properties of packagemanger tell when might complete, can rely on surrogates such when sd card mounted or when media scanner service has finished. better arbitrary delay after boot, best answer have found far.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -