1.將Billing Sample src裡的com.android.vending.billing複製到你的專案裡
2.在AndroidManifest.xml裡的user-permission添加
com.android.vending.BILLING
註︰如果沒有宣告就請求billing機制時,將會收到
RESULT_DEVELOPER_ERRO反應
3. 建立BroadcastReceiver和Service(見步驟4)
BroadcastReceiver - 用來處理從Android Market傳來的Billing訊息
Service - 綁剛才從billing sample src複製過來的IMarketBillingService.aidl
哦!對了。AndroidManifest.xml裡的BroadcastReceiver要設
intent filters
4.攢寫Service
這個Service將要做哪些事?
(1)綁定IMarketBillingService.aidl
(2)向Android Market發佈Billing請求
CHECK_BILLING_SUPPORTED
requestsREQUEST_PURCHASE
requestsGET_PURCHASE_INFORMATION
requestsCONFIRM_NOTIFICATIONS
requestsRESTORE_TRANSACTIONS
requests
============================
(1)綁定IMarketBillingService.aidl詳細說明
建立一個Service並實作serviceConnection,然後將底下的Code放進OnCreate()
建立callback(將以下程式碼貼進自創的Service裡)
可以開始用mService去
sendBillingRequest()任何需求了!
try { boolean bindResult = mContext.bindService( new Intent("com.android.vending.billing.MarketBillingService.BIND"), 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); }
/** * The Android system calls this when we are connected to the MarketBillingService. */ public void onServiceConnected(ComponentName name, IBinder service) { Log.i(TAG, "MarketBillingService connected."); mService = IMarketBillingService.Stub.asInterface(service); }
記得將developer發佈頁面裡的公開金鑰放進Security.java裡的base64EncodedPublicKey變數中
No comments:
Post a Comment