应用内购买服务有时会被关闭

5

您好,我们在市场上发布了这个应用程序,并使用了应用内购买功能。我们的日志显示,某些客户设备上的BillingService(可能是应用程序本身)会随机关闭。因此,有时我无法收到购买是否成功的通知。一些客户经常不得不购买两次才能成功购买。虽然这只发生在少数客户身上,但仍然令人困扰。您有什么想法为什么会发生这种情况,或者可以采取什么措施来解决这个问题吗?


1
它在哪个过程中被终止了?通常情况下,它会从Android市场广播通知开始 -> 您的BillingReceiver onReceived() -> BillingReceiver将购买意图发送到BillingService -> BillingService处理并更新购买信息。 - Frank Leigh
事情是相当随机的,而且我还没有在我的设备上重现这个问题。虽然只会影响少数用户,但我仍然想要解决它。 - the100rabh
随机性确实使其更加困难 :) 你能在应用中添加更多的跟踪信息吗?Acra是我发现非常有用的错误跟踪工具。此外,也可能是过于激进的任务管理器应用导致的问题。 - Frank Leigh
ACRA确实存在于应用程序中,但它也无法报告任何内容。 - the100rabh
@the100rabh,你的问题解决了吗? - Arash
不,问题没有得到解决,直到谷歌发布了新版本的PlayStore应用程序。 - the100rabh
2个回答

2
我不确定这是否有帮助,但我建议将您的BillingService前台服务化:http://developer.android.com/guide/components/services.html#Foreground 以下是文档片段:“API可将服务置于前台状态,在此状态下,系统认为用户正在积极意识到它,因此在内存不足时不会杀死该服务。 ”
可能是您的一小部分用户存在低内存条件,因此开始终止服务/应用程序(包括您自己的)。

是的,你说得没错,内存不足可能是问题所在。但把它作为前台进程运行确实是个好建议。这样或许会有所帮助。但事实上,整个进程似乎都重新启动了,而不仅仅是服务。 - the100rabh
如果此时您没有前台活动(或服务),系统可能会(并且很可能会)在低内存情况下杀死整个进程。 - Victor Ronin

0
你能提供一下你在应用内购买中使用的代码吗?可能是因为他们的设备不支持应用内购买,或者当他们尝试访问Android市场广播通知时失去了互联网连接。我在我的应用程序中使用的基本上就是这样的:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if( BillingHelper.isBillingSupported()){
        switch (arg2) {
        case 0:         
            Log.d("Appname", "30 coins");
            BillingHelper.requestPurchase(context, "com.paid.smallcoinbundle"); 
                 break;
        case 1: 
            Log.d("Appname", "85 coins");
            BillingHelper.requestPurchase(context, "com.paid.medcoinbundle"); 
                 break;
        case 2: 
            Log.d("Appname", "175 coins");
            BillingHelper.requestPurchase(context, "com.paid.midcoinbundle"); 
                 break;
        case 3:  
            Log.d("Appname", "500 coins");
            BillingHelper.requestPurchase(context, "com.paid.maxcoinbundle"); 
                 break;
        default: Log.d("Appname", "Something broke");
        break;
        }
    //  BillingHelper.requestPurchase(mContext, "android.test.purchased"); 
        // android.test.purchased or android.test.canceled or android.test.refunded or com.blundell.item.passport
    } else {
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.toast_layout,(ViewGroup) findViewById(R.id.toast_layout_root));
        TextView text = (TextView) layout.findViewById(R.id.text);
        text.setText("In App Billing isnt supported by your device");
        Toast toast = new Toast(getBaseContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();
        return;
    }
}

然后:

public Handler mTransactionHandler = new Handler(){
    public void handleMessage(android.os.Message msg) {
        Log.d("Appname", "Transaction complete");
        Log.d("Appname", "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
        Log.d("Appname", "Item purchased is: "+BillingHelper.latestPurchase.productId);

        if(BillingHelper.latestPurchase.isPurchased()){
            Log.d("Appname", "Ispurchased : " + BillingHelper.latestPurchase.productId);
            if(BillingHelper.latestPurchase.productId.equals("com.paid.smallcoinbundle")){
                ConnectToServer.UpdateCoins(context,id,"add","30");
            }
            if(BillingHelper.latestPurchase.productId.equals("com.paid.medcoinbundle")){
                ConnectToServer.UpdateCoins(context,id,"add","85");
            }
            if(BillingHelper.latestPurchase.productId.equals("com..paid.midcoinbundle")){
                ConnectToServer.UpdateCoins(context,id,"add","175");
            }
            if(BillingHelper.latestPurchase.productId.equals("com.paid.maxcoinbundle")){
                ConnectToServer.UpdateCoins(context,id,"add","500");
            }

            finish();
        }
    };

};

因为你说应用内购买确实有效,尽管有时候他们需要购买两次商品,我认为你的包名应该是正确的。

请告诉我你是如何解决这个问题的,以及问题是什么。这是一个非常有趣的话题。


这确实很有趣,代码似乎直接从谷歌示例代码中提取。对于大多数用户来说,它完美地运行。但是少数用户遇到了这个问题。 - the100rabh
在这种情况下,那可能是系统出现了错误。请给开发团队编写一个错误报告。很抱歉我无法帮助你。 - Ushal Naidoo
嗨,Randy,谢谢你尝试帮助我 :) - the100rabh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接