设备上的其它应用的计算哈希值 [英] Compute hash value of other application on device

查看:151
本文介绍了设备上的其它应用的计算哈希值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Android应用程序,需要保持一些安装在设备上的其他应用程序的轨道。

I am building an Android application that needs to keep track of some of the other applications installed on the device.

有关给定应用(包)我需要计算一个散列值,使得:

For a given application (package) I need to compute a hash values such that:


  • 的值是不同版本的同一应用程序
  • 的不同
  • 的值是安装在不同的设备相同的版本相同的应用程序的相同

有没有有效地这样做的方法吗?

Is there a way of doing this efficiently?

感谢您

推荐答案

只需加载APK作为一个文件,并计算文件的MD5哈希值:

Simply load the apk as a file and compute the MD5 hash of the file with:

public String md5(String s) {
    try {
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuffer hexString = new StringBuffer();
        for (int i=0; i<messageDigest.length; i++)
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

来自的http:/ /www.androidsnippets.com/create-a-md5-hash-and-dump-as-a-hex-string

更新
你只是想看看是否已经安装一个App的新版本,为什么不使用 PackageManager.getPackageInfo 的方法?它返回一个包含应用程序的版本号的 PackageInfo 对象。你可以跟踪这些数据,并使他们改变就意味着一个应用程序已更新。看到这一点: http://developer.android.com/reference/android/内容/ PM / PackageManager.html

Update: Are you simply trying to see if a newer version of an App has been installed why not use the PackageManager.getPackageInfo method? It returns a PackageInfo object that contains the version number of the application. You can track these values and when they change it means that an app has been updated. See this: http://developer.android.com/reference/android/content/pm/PackageManager.html

这篇关于设备上的其它应用的计算哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆