我使用BroadcastReceiver
来注册添加包的事件,一旦我得到该事件,我就用getApplicationInfo调用包管理器,以获得有关已安装包的更多信息。此时,我收到namenoutfoundexception,我相信这是因为包管理器没有更新数据,而我在它之前得到了事件。我该如何解决这个问题?有什么想法吗?
我的代码:
public void onReceive(Context context, Intent intent) {
// Launch the activity for showing reputation of application
Intent intent1 = new Intent(ApplicationListViewActivity.this,AppViewActivity.class);
//Next create the bundle and initialize it
Bundle bundle = new Bundle();
String pkgName = intent.getData().toString();
//Add the parameters to bundle as
bundle.putString("pkgName",pkgName);
//Add this bundle to the intent
intent1.putExtras(bundle);
startActivity(intent1);
}
try {
ApplicationInfo ai = pm.getApplicationInfo(pkgName, PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
{//end up here}
发布于 2012-12-06 21:02:56
pkgName
看起来像这样:package: com.your.package.name
,您所需要做的就是删除package:
。
你可以这样做:
int pos = pkgName.indexOf(':');
if(pos>=0) {
pkgName = pkgName.substring(pos + 1);
}
祝你编码愉快。
https://stackoverflow.com/questions/9323059
复制相似问题