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;
}
}