检测,如果应用程序是从Android Market下载 [英] Detect if app was downloaded from Android Market

查看:108
本文介绍了检测,如果应用程序是从Android Market下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android库,上传数据到测试服务器和生产服务器。我会使用这个库一起使用时,开发测试服务器和生产服务器,当应用程序被从Android Market下载喜欢的开发者。

I have an Android library that uploads data to a test server and production server. I'd like developers using this library to use the test server when developing, and production server when the app is downloaded from Android Market.

这是可能的一个应用程序告诉它来自何处(市场或非市场?)我会想象人们可以检测到签名的JAR文件的presence。

Is this possible for an app to tell where it came from (Market or non-Market?) I would imagine one could detect the presence of the signed JAR file.

推荐答案

是的,你可以使用这个签名。如果您使用的是调试重点开发和释放键时上传您的应用程序推向市场时,签上你的应用程序,你可以检查该应用程序是有符号和基于使用测试或生产服务器上的签名。 这里是一个小code片来读取你的应用程序的签名:

Yes, you could use the signature for that. If you use a debug key to sign your app during development and a release key when uploading your app to the market you can check for the signature that the app was signed with and based on that use test or production server. Here is a small code piece to read the signature of your app:

    try {
        PackageManager manager = context.getPackageManager(); 
        PackageInfo appInfo = manager.getPackageInfo(
            YOUR_PACKAGE_NAME, PackageManager.GET_SIGNATURES);

        // Now test if the first signature equals your debug key.
        boolean shouldUseTestServer = 
            appInfo.signatures[0].toCharsString().equals(YOUR_DEBUG_KEY);

    } catch (NameNotFoundException e) {
        // Expected exception that occurs if the package is not present.
    }

YOUR_PACKAGE_NAME必须像​​com.wsl.CardioTrainer。它必须是在你的Andr​​oidManifest.xml中使用的包名。 好运

YOUR_PACKAGE_NAME must be something like 'com.wsl.CardioTrainer'. It must be the package name you used in your AndroidManifest.xml. Good Luck

标记

这篇关于检测,如果应用程序是从Android Market下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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