我有应用程序检查应用程序是否安装并使用此布尔值
final boolean b1 = appInstalledOrNot("com.whatsapp");
.....
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
}
我想将布尔值转换为字符串并获取正确的值。我尝试了这个,但如果我想删除应用程序,请收到错误“找不到包”
String str = String.valueOf(b1);
答案 0 :(得分:1)
This is how you can modify your approach
PackageInfo pinfo;
try {
pinfo = getPackageManager().getPackageInfo("Your package name", 0);
}
catch (NameNotFoundException e1) {
pinfo = null;
}
if(pinfo!=null)
{
**"Installed"**
}
else
{
"Not Installed"
}
我不明白为什么你接近这样,这将给出最好的结果。 检查一下。这就是我们如何将我们的包与playstore中的包进行比较。
public String getSignature(String pkgName) throws NameNotFoundException {
PackageInfo pi = pkgMngr.getPackageInfo(pkgName, GET_SIGNATURES);
String signature = pi.signatures[0].toCharsString();
return signature;
}
public boolean doSignaturesMatch(String pkg1, String pkg2) {
boolean match = pkgMngr.checkSignatures(pkg1, pkg2) == SIGNATURE_MATCH;
return match;
}
public boolean isInstalledFromMarket(String pkgName)
throws NameNotFoundException {
String installerPkg = pkgMngr.getInstallerPackageName(pkgName);
boolean installedFromMarket = "com.google.android.feedback"
.equals(installerPkg);
答案 1 :(得分:0)
String booleanString = Boolean.toString(boolValue)