Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get installed application name in android?

I have made a small method to display the installed application name in android. But when i give "name" attribute its showing exception error. And when i give "packageName" the method executes perfectly and displays the package name in a list

private void getInstalledApps() {
    // TODO Auto-generated method stub
     PackageManager packageManager=this.getPackageManager();
        List<ApplicationInfo applist=packageManager.getInstalledApplications(0);


        Iterator<ApplicationInfo> it=applist.iterator();
        while(it.hasNext()){
            ApplicationInfo pk=(ApplicationInfo)it.next();

            String appname=pk.name.toString();

            installedapplist.add(appname);
        }

}

In the above code when i give String appname=pk.packageName.toString() it works fine but when I give String appname=pk.name.toString() the program is throwing an exception error. Please help me to sort out the problem.

like image 390
Unnikrishnan Avatar asked Jul 27 '11 00:07

Unnikrishnan


1 Answers

My guess is your code is throwing a NullPointerException because the name field is null. In any event, what you probably want is:

String appname = packageManager.getApplicationLabel(pk).toString()
like image 113
Ted Hopp Avatar answered Oct 15 '22 11:10

Ted Hopp