如何在同一个 APK 中支持 Amazon 和 Android Market (Google Play) 链接 [英] How to support Amazon and Android Market (Google Play) links in same APK

查看:33
本文介绍了如何在同一个 APK 中支持 Amazon 和 Android Market (Google Play) 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
支持应用内的亚马逊和安卓市场链接

我想知道您是否以及如何区分亚马逊应用商店安装的应用和市场上安装的应用.

I was wondering if and how you could differentiate between an Amazon App Store installed app and one installed from the Market.

例如,假设我有一个名为Example App"的应用程序,我想为亚马逊和市场开发.在应用程序中,我有链接来评价示例应用程序.我也有购买 Example App Pro 的链接.这带来了一个问题,因为如果我的应用链接到不同的应用商店,亚马逊将不会发布它.

For example, say I have my app called "Example App", and I want to develop for Amazon and the Market. In the app I have links to rate Example App. I also have a link to buy Example App Pro. This poses a problem because Amazon will not release my app if it links to a different App store.

这需要我制作2个APK文件,很痛苦.导出两者仅需要大约 30 秒的额外时间,但这会造成额外的混乱和测试时间.

This requires me to make 2 APK files, which is a pain. It only takes about 30 seconds extra to export both, but it creates extra clutter and testing time.

所以有没有人找到一种方法来制作一个可以同时上传到亚马逊和安卓市场的 APK,而无需在两者之间进行任何更改,以便在运行时我可以检查是亚马逊还是市场安装了它并且相应地更改链接?

So has anyone found a way to make a single APK that can be uploaded to both Amazon and Android Market without making any changes between the two so that at run time I can check whether it's the Amazon or the Market that installed it and change the links accordingly?

推荐答案

在写这篇文章的时候,我并不知道,但确实存在 getInstallerPackageName() 但我不确定这有多可靠.我也不确定它对亚马逊/市场等的回报是什么.它可能值得一看,但如果它不起作用,那么下面的方法适用于谷歌 vs 亚马逊.

At the time of this post, I wasn't aware of it, but there does exist getInstallerPackageName() but I'm not sure how reliable that is. I'm also not sure what it returns for Amazon / Market, etc. It might be worth looking at, but if it doesn't work, then the below method works for Google vs Amazon.

您必须照常签署应用程序,在您的测试设备上运行,从您的日志中获取 sig.hashCode() 的值,然后将 -1545485543 替换为您为 sig.hashCode() 获得的任何值,然后导出并再次签名(使用与之前相同的密钥),然后从同一个 APK 上传到亚马逊和市场.

You will have to sign the application as normal, run on your test device, get the value of sig.hashCode() from your logs, then replace -1545485543 with whatever value you got for sig.hashCode() then export and sign again (WITH THE SAME KEY AS BEFORE) and then upload to Amazon and Market both - from the same APK.

去做:

public static boolean isMarket(Context context){
    boolean isMarketSig = false;
    int currentSig = 1; // I just set this to 1 to avoid any exceptions later on.
    try {
        Signature[] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        for (Signature sig : sigs)
        {
            currentSig = sig.hashCode();


    Log.i("MyApp", "Signature hashcode : " + sig.hashCode());
// This Log is for first time testing so you can find out what the int value of your signature is.
            }
            } catch (Exception e){
                e.printStackTrace();


}
//-1545485543 was the int I got from the log line above, so I compare the current signature hashCode value with that value to determine if it's market or not.
        if (currentSig==-1545485543){
            isMarketSig = true;
    } else {
        isMarketSig = false;
    }

    return isMarketSig;
}
public static void openStore(Context context){
    if (isMarket(context)){
        Intent goToMarket = new Intent(Intent.ACTION_VIEW,Uri.parse("market://d" +
        "etails?id=com.jakar.myapp"));
        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(goToMarket);  
    } else {
        Intent goToAppstore = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.amazon.com/gp/mas/dl/andro" +
        "id?p=com.jakar.myapp"));
        goToAppstore.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(goToAppstore);
    }
}

基本上,您从安装在测试设备上的应用程序获得的 hashCode() 与市场上的相同.来自应用商店的哈希码会有所不同,因为根据 https://developer.amazon.com/help/faq.html,应用商店使用特定于您的开发者帐户的签名对应用程序进行签名,以便返回与您实际签名时使用的值不同的值.

Basically, the hashCode() that you get from the app installed on your testing device will be the same one from the market. The hash code from the app store will be different because according to https://developer.amazon.com/help/faq.html, the app store signs the application with a signature specific to your developer account, so that will return a different value that what you actually signed it with.

我将 isMarket 和 openStore 方法放在一个名为 OtherClass 的不同类中,这样我只需编码一次.然后从我需要打开正确链接的任何活动中,我只需调用 OtherClass.openStore(context);

And I put the isMarket and openStore methods in a different class called OtherClass so that I only have to code it once. Then from any activity where I need to open the proper link, I just call OtherClass.openStore(context);

注:可以成功开市,但是我还没有在App Store上部署这个方法,所以没有完全测试过.我相信它会起作用,但不能保证,所以如果你使用我的建议但它失败了,请不要追究我的责任.

Note: It works to open the market successfully, but I haven't yet deployed this method on the App Store, so I haven't completely tested it. I am confident it will work, but can make no guarantees, so if you use what I've suggested and it fails, please don't hold me accountable.

对提出一个答案,以便我可以测试正在使用哪个签名.

This was a big help in coming up with an answer so I could test which signature was being used.

这篇关于如何在同一个 APK 中支持 Amazon 和 Android Market (Google Play) 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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