首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android InAppBilling onServiceConnected从未调用过

Android InAppBilling onServiceConnected从未调用过
EN

Stack Overflow用户
提问于 2013-06-20 10:59:09
回答 1查看 548关注 0票数 3

尝试在我正在开发的应用程序中添加一些购买应用程序,但事情进展不是很顺利。

我有一个这样的FragmentActivity:

代码语言:javascript
复制
public class TestInAppBilling extends FragmentActivity{

//Application context reference
private static Context context;

/*
Billing stuff
 */
private IInAppBillingService mService;
private ServiceConnection mServiceConn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_layout);

    context = getApplicationContext();

    if(mServiceConn == null){
        mServiceConn = new ServiceConnection() {
            @Override
            public void onServiceDisconnected(ComponentName name) {
                mService = null;
            }

            @Override
            public void onServiceConnected(ComponentName name,
                                           IBinder service) {
                mService = IInAppBillingService.Stub.asInterface(service);
                System.out.println("Bound!");
            }
        };

        context.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    if (mServiceConn != null) {
        unbindService(mServiceConn);
    }
}
}

但由于某些原因,onServiceConnected回调从未发生过。

有人知道是什么引起的吗?

EN

回答 1

Stack Overflow用户

发布于 2017-02-08 07:23:43

我想你已经解决了。无论如何,我有同样的问题,我只是解决了它。要使其正常工作,请删除此行:

代码语言:javascript
复制
context.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);

并添加以下内容:

代码语言:javascript
复制
setContentView(R.layout.test_layout);
context = getApplicationContext();
Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
intent.setPackage("com.android.vending");
getContext().bindService(intent, mServiceConn, getActivity().BIND_AUTO_CREATE);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17204594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档