【问题标题】:Find App is already installed or not..?查找应用程序是否已安装..?
【发布时间】:2017-08-05 17:56:56
【问题描述】:

我浏览了很多链接和教程,例如 Check if application is installed - AndroidHow to check programmatically if an application is installed or not in Android?,但我没有找到我的问题的确切解决方案。当我尝试安装启动程序包为 com.test.app 的应用程序时,我想在安装时检查此程序包,或者您可以说我们的应用程序是否已安装? 当我尝试按照上面的链接进行操作时,无论是否已安装,它总是为我显示“已安装”。那么我将如何管理它。

【问题讨论】:

  • 好的,我有解决方案,我给你一个链接,提供所有已安装的应用程序名称、包名称和其他信息。你可以在那里检查特定的包名称。如果你有任何问题告诉我。
  • 首先你应得的......感谢您的快速回复......
  • 嘿 gopal RAO.. 是否可以在安装应用程序“A”的过程中检查应用程序“A”是否安装......?通过使用一些 SYSTEM_SERVICE 是可能的吗?我不知道它....
  • 是的,我明白了。我可以通过使用网络服务来做到这一点。谢谢大家..

标签: android installation


【解决方案1】:

这是一个想法。我已经实现了

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

【讨论】:

  • 请告诉我我的想法是否可行?
  • 一般情况下,GooglePlay 应用会负责更新真实设备中的应用。我们无需手动检查应用程序的更新,因为这是 GooglePlay 应用程序的责任。我不能说这是否可行,因为我从来没有遇到过这种情况......
  • 是的..当然..你可以问
猜你喜欢
  • 2017-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
相关资源
最近更新 更多