Android PackageManger - NameNotFound异常

时间:2012-02-17 04:48:31

标签: android

我正在使用BroadcastReceiver注册包添加事件,一旦我收到该事件,我就会使用getApplicationInfo调用包管理器以获得有关安装包的更多信息。这时我收到namenoutfoundexception,我相信这是因为packagemanager没有更新数据,我之前得到了事件。我该如何解决这个问题?有什么想法吗?

我的代码:

 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}

1 个答案:

答案 0 :(得分:1)

pkgName如下所示:package: com.your.package.name,您需要做的就是删除package:

你可以这样做:

int pos = pkgName.indexOf(':');
if(pos>=0) {
    pkgName = pkgName.substring(pos + 1);
}

快乐的编码。