Michelle
Michelle

Reputation: 2900

Known package name not found with package manager

I've got a broadcast receiver that gets "android.intent.action.PACKAGE_ADDED" and "android.intent.action.PACKAGE_REPLACED" intents (so when a package is installed on the phone, my app gets an intent with the package name). But when I try to use the PackageManager to get the PackageInfo by package name, it's throwing a NameNotFoundException.

What reasons might there be for this (other than the package not existing, which obviously isn't the case)? I can't find much on permissions - is there one I'm missing that's causing a misleading error?

try {
    id = UAppIDUtils.GetUAppID(ctx.getPackageManager().getPackageInfo(pkgName, PackageManager.GET_SIGNATURES));
} catch (NameNotFoundException e) {
    id = null;
    Log.v(TAG, "Error finding package info");
    e.printStackTrace();
}

ctx is the context; pkgName is the package name.

Upvotes: 1

Views: 4124

Answers (2)

Chris Klingler
Chris Klingler

Reputation: 5296

One really annoying time that I ran into this error was because the package name for the app that I was trying to find/intent over to had hidden characters in the text that I copied. Just to be careful retype out your package name or do a log to see what package name you are really looking for as it might not be what you think.

Upvotes: 0

Michelle
Michelle

Reputation: 2900

Figured it out - it turns out that the string shipped with the PACKAGE_ADDED intent starts with "package:" and then the package name - I hadn't caught it because it didn't stand out in my print statements as something I hadn't written. Just needed to strip the label off the start of the data string and I was good to go.

Upvotes: 1

Related Questions