Android 中的应用程序计费

发布于 2024-10-27 11:11:13 字数 882 浏览 0 评论 0原文

我正在使用以下代码:

public class MyBillingService extends Service implements ServiceConnection
{
    String TAG = "MyBillingService";

    @Override
    public void onCreate() 
    {
        super.onCreate();
        Log.i(TAG, "onCreate");

        try {
            boolean bindResult = getBaseContext().bindService(
                new Intent(IMarketBillingService.class.getName()), this, Context.BIND_AUTO_CREATE);
            if (bindResult) {
                Log.i(TAG, "Service bind successful.");
            } else {
                Log.e(TAG, "Could not bind to the MarketBillingService.");
            }
        } catch (SecurityException e) {
            Log.e(TAG, "Security exception: " + e);
        }
    }
}

我还添加了 IMarketBillingService.aidl 但它仍然显示为:

无法绑定到 市场计费服务

你能指出我的错误吗?

I am using following code:

public class MyBillingService extends Service implements ServiceConnection
{
    String TAG = "MyBillingService";

    @Override
    public void onCreate() 
    {
        super.onCreate();
        Log.i(TAG, "onCreate");

        try {
            boolean bindResult = getBaseContext().bindService(
                new Intent(IMarketBillingService.class.getName()), this, Context.BIND_AUTO_CREATE);
            if (bindResult) {
                Log.i(TAG, "Service bind successful.");
            } else {
                Log.e(TAG, "Could not bind to the MarketBillingService.");
            }
        } catch (SecurityException e) {
            Log.e(TAG, "Security exception: " + e);
        }
    }
}

I have also added the IMarketBillingService.aidl but still it show like:

Could not bind to the
MarketBillingService

Can you point out my mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-11-03 11:11:13

我不知道这是否是您问题的原因,但您正在 getBaseContext() 上使用 bindService() 。您不在服务实例上调用bindService() 是否有原因?这就是示例服务的作用。

基本上下文似乎基本上是不需要的,一般建议似乎不使用它。
请参阅另一个问题:有什么区别 。

除此之外,您需要在设备上安装最新(或至少是最近)版本的 Android Market 应用程序,尽管我假设它会自行更新

有一种方法可以测试市场应用程序是否支持应用程序内结算,在应用程序内结算参考中的某处进行了描述。我认为做这项检查是值得的。

I don't know if this is the cause for your problem, but you are using bindService() on getBaseContext(). Is there a reason that you don't call bindService() on the service instance? That's what the example service does.

The base context seems to be mostly unneeded and the general advice seems to not use it.
See the other question: What's the difference between the various methods to get a Context?

Besides that, you need to have the newest (or at least a recent) version of the Android Market App on your device, although I assume that it updates itself.

There is a way to test if the market app supports In-App Billing, somewhere described in the In-App-Billing reference. I assume that it is worth to do that check.

陌上芳菲 2024-11-03 11:11:13

我正在一台旧的 Android 设备上进行测试,该设备安装了干净的系统。这上面没有 Google Market 应用程序的副本(帽子提示@sstn)。

所以我用谷歌帐户登录,然后启动了市场。这促使我同意条款,Google Play 应用程序出现在应用程序列表中。

然后我删除并重新安装了我的应用程序,它正确绑定到服务!

I was testing on an old Android device which had a clean system install. This didn't have a copy of the Google Market app on it (hat tip @sstn).

So I logged in with a Google account, then launched the Market. That prompted me to agree to terms and the Google Play app appeared in the list of applications.

Then I removed and reinstalled my app and it bound to the service correctly!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文