Google Paly V3 Initate Connect & Query Items
来源:互联网 发布:域普软件怎样 编辑:程序博客网 时间:2024/05/29 03:07
Initiate a Connection with Google Play
Creating a ServiceConnection
Your application must have a ServiceConnection
to facilitate messaging between your application and Google Play. At a minimum, your application must do the following:
- Bind to
IInAppBillingService
. - Send billing requests (as IPC method calls) to the Google Play application.
- Handle the synchronous response messages that are returned with each billing request.
Binding to IInAppBillingService
To establish a connection with the In-app Billing service on Google Play, implement a ServiceConnection
to bind your activity to IInAppBillingService
. Override the onServiceDisconnected
and onServiceConnected
methods to get a reference to the IInAppBillingService
instance after a connection has been established.
IInAppBillingService mService;ServiceConnection mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IInAppBillingService.Stub.asInterface(service); }};
In your activity’s onCreate
method, perform the binding by calling the bindService
method. Pass the method anIntent
that references the In-app Billing service and an instance of the ServiceConnection
that you created.
@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
IabHelper
instance in your activity'sonCreate
method. In the constructor, pass in the Context
for the activity, along with a string containing the public license key that was generated earlier by the Google Play Developer Console.IabHelper mHelper;@Overridepublic void onCreate(Bundle savedInstanceState) { // ... String base64EncodedPublicKey; // compute your public key and store it in base64EncodedPublicKey mHelper = new IabHelper(this, base64EncodedPublicKey);}
2、Next, perform the service binding by calling the
startSetup
method on theIabHelper
instance that you created. Pass the method anOnIabSetupFinishedListener
instance, which is called once theIabHelper
completes the asynchronous setup operation. As part of the setup process, theIabHelper
also checks if the In-app Billing Version 3 API is supported by Google Play. If the API version is not supported, or if an error occured while establishing the service binding, the listener is notified and passed anIabResult
object with the error message.mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // Oh noes, there was a problem. Log.d(TAG, "Problem setting up In-app Billing: " + result); } // Hooray, IAB is fully set up! }});Query Items Available for Purchase
1、You can query Google Play to programmatically retrieve details of the in-app products that are associated with your application (such as the product’s price, title, description, and type). This is useful, for example, when you want to display a listing of unowned items that are still available for purchase to users.
Note: When making the query, you will need to specify the product IDs for the products explicitly. You can manually find the product IDs from the Developer Console by opening the In-app Products tab for your application. The product IDs are listed under the column labeled Name/ID.
To retrieve the product details, call
queryInventoryAsync(boolean, List, QueryInventoryFinishedListener)
on your IabHelper instance.
- The first input argument indicates whether product details should be retrieved (should be set to
true
). - The
List
argument consists of one or more product IDs (also called SKUs) for the products that you want to query. - Finally, the
QueryInventoryFinishedListener
argument specifies a listener is notified when the query operation has completed and handles the query response.
The following code shows how you can retrieve the details for two products with IDs SKU_APPLE
and SKU_BANANA
that you previously defined in the Developer Console.
List additionalSkuList = new List();additionalSkuList.add(SKU_APPLE);additionalSkuList.add(SKU_BANANA);mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
- Google Paly V3 Initate Connect & Query Items
- 我是这样在Google paly上赚美刀的
- App don't display in google paly
- google paly 应用推广 发送渠道广播
- web爬虫之登录google paly 商店
- Android 中 使用 Google Paly 支付 简介
- 跳到google paly应用代码
- 将Google Paly 上apk下载至PC本地
- Android Play V3 Querying for Items
- Android Play V3 Querying for Purchased Items
- mysql connect query
- Query DynamoDB Items with Java By QueryRequest
- Google Maps API V3
- google map api v3
- Google Map API V3
- google maps v3 示例
- google v3 mapTypeId
- google Maps V3测距
- 线性表——1. 顺序表(向量)
- ubuntu服务器配置
- JAVA中SERIALVERSIONUID的解释
- 鬼脚七之“寒门再难出贵子”---一篇值得一读的好文章,比小说还精彩的现实故事(转载)
- c# 二维数组 行列
- Google Paly V3 Initate Connect & Query Items
- poj 1844 sum (数学)
- ora-00257:归档程序错误,在释放之前仅限于内部链接如何解决
- 这些技能你两周能不能学会,以此来检测你将来是否有潜力成为IT大神
- XAML Binding的几个元素
- 消息与事件的区别
- android:sharedUserId和签名证书
- 全面解析Java的垃圾回收机制
- C/C++面试题精选