1

Please I want to create a condition that will give a toast if when it checks through the applications in the android device will notify the user if such an application is installed in the device. Note that I don't want to display the list of installed applications I just want to create a condition that will check through all the applications in the device. I have written the code given below but I seem not to be getting the desired result. Please can someone help me with the modification or a better solution.

String applicationName;
getApplicationName(holder.Text_Name.toString());

if(applicationName.contains(holder.Text_Name.toString())) {
    Toast.makeText(getApplicationContext(), "Application Installed",Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(getApplicationContext(), "Application Not Installed",Toast.LENGTH_SHORT).show();
}

}


});

}

private  void getApplicationName(String Text_Name) {

    PackageManager packageManager=getPackageManager();
    List<PackageInfo>packs=packageManager.getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p=packs.get(i);
       if(p.applicationInfo.name==Text_Name)
        applicationName=Text_Name;

    }
}
net_whiz
  • 135
  • 2
  • 15

1 Answers1

0

First of all there is no need to use Static variable. You can build a method, where in pass the application you are looking for and search through the list of applications already installed. Once desired app is find you can show toast then and there..

You can use below link to check how to find installed apps

How to get a list of installed android applications and pick one to run

Community
  • 1
  • 1
Iotasol
  • 11
  • 2
  • thanks but I have used those codes but seem not to be getting the result. I have also removed the static it was a typographical error – net_whiz Feb 16 '12 at 13:33