如何支持亚马逊和Android Market(谷歌播放)在同一APK链接 [英] How to support Amazon and Android Market (Google Play) links in same APK

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

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/5480235/supporting-amazon-and-android-market-links-inside-application">Supporting亚马逊和Android应用程序内市场联系

Possible Duplicate:
Supporting Amazon and Android market links inside application

我在想,如果,你怎么会在亚马逊的App Store区分安装的应用程序,并从市场安装一个。

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

举例来说,假设我有我的应用程序称为示例应用程序,我想开发亚马逊和市场。在应用程序我有联系率的示例应用程序。我也有一个链接购买示例应用程序专业版。这就带来了一个问题,因为亚马逊不会释放我的应用程序,如果它链接到不同的应用程序商店。

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.

那么有没有人找到了一种方法,使可上传到亚马逊和Android的市场未做任何两者之间的变化,这样在运行时单个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.hash code值(),那么无论你的价值得到了sig.hash $替换为-1545485543 C $ C(),然后出口和再签收(使用相同的密钥和以前一样),然后上传到亚马逊和市场两个 - 来自同一个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);
    }
}

基本上,哈希code(),您从安装在测试设备​​上的应用程序,得到的将是同一个从市场。从App Store中的散列code会有所不同,因为根据的https://developer.amazon .COM /帮助/的faq.html ,App Store的迹象,具体到你的开发者个人签名的应用程序,这样就会返回不同的值,你居然跟签了字。

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.

和我放在一个不同的类称为OtherClass的isMarket和openStore方法,使我只需要$ C C $它一次。然后从那里我需要打开适当的链接的任何活动,我只是叫OtherClass.openStore(上下文);

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.

<一个href="http://stackoverflow.com/questions/5578871/android-how-to-get-app-signature/5579239#5579239">This在想出一个答案,所以我可以测试正在使用该签名有很大的帮助。

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

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

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