我经历了很多链接和教程,例如Check if application is installed - Android和How to check programmatically if an application is installed or not in Android?,但我没有找到问题的确切解决方案。当我试图安装其启动程序包为com.test.app的应用程序时,那么在安装时我想检查这个程序包,或者你可以说我们的应用程序已经安装好了吗? 当我尝试按照上面的链接进行操作时,无论是否已安装,我都会显示“已安装”。那么我将如何管理这个。
答案 0 :(得分:0)
这是一个想法。我已经实施了
1. Create a Web Service which our app can pull whenever the app
launches or based on some time limit that can check if there is new version out there.
2. This Web service should return the latest Version of the apk file that is hosted on the
Server along with the URI of the application file that has the new version.
3. When your app gets the response from the Web Service, it will parse the JSON and
check our app version to the latest version that is available
on the server.
4. If our app version is lower than the latest version it will prompt
the user to start the download process.
5. Today i manage download process by the Download Manager and day before
yesterday I do same thing by Package Manager. I will update which mechanism is
most optimal to download .apk file with size of more than 10MB.
6. The download manager will notify our app using Broadcast receiver when the download
is complete.
7. Upon completion of the latest version of the application file the we can
start the activity to install that file.
然后我们可以通过
比较版本 private static int compare(String v1, String v2) {
String s1 = normalisedVersion(v1);
String s2 = normalisedVersion(v2);
int cmp = s1.compareTo(s2);
System.out.println("cmp int "+cmp);
return cmp;
/* String cmpStr = cmp < 0 ? "<" : cmp > 0 ? ">" : "==";
System.out.printf("'%s' %s '%s'%n", v1, cmpStr, v2);*/
}
然后
public static String normalisedVersion(String version) {
return normalisedVersion(version, ".", 4);
}
public static String normalisedVersion(String version, String sep, int maxWidth) {
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(String.format("%" + maxWidth + 's', s));
}
return sb.toString();
}