Hi..
Just a general tip:
It's better to put the use/printout within the try statement (or exit
the function etc if it catches the error), as pInfo (in this case)
would be null if the info isn't found, and then you get a
NullException instead...
so, either:
try {
pInfo = getPackageManager().getPackageInfo("com.beanie.test",
PackageManager.GET_META_DATA);
System.out.println(pInfo.versionCode);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
or:
try {
pInfo = getPackageManager().getPackageInfo("com.beanie.test",
PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
e.printStackTrace();
return; /* return false; or return null; */
}
System.out.println(pInfo.versionCode);
Just something to remember, so you don't introduce one extra
(unnecessary) possible exception/bug, that you need to catch, while
catching another exception...
Regards
Chris
On Jan 24, 5:11 am, Kumar Bibek <[email protected]> wrote:
> PackageInfo pInfo = null;
>
> try {
> pInfo = getPackageManager().getPackageInfo("com.beanie.test",
> PackageManager.GET_META_DATA);
>
> } catch (NameNotFoundException e) {
> e.printStackTrace();}
>
> System.out.println(pInfo.versionCode);
>
> Kumar Bibek
>
> On Jan 24, 8:48 am, dapaintballer331 <[email protected]>
> wrote:
>
> > How do you retrieve the current version code of an app's manifest?
> > I don't need to access another application, I'm talking about My app
> > accessing its own version code.
>
> > Thanks
> > -Brandon
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en