2013年2月19日火曜日

Android Subscriptions(API Version3)の実装

2/1 に Android アプリ内課金(API Version3)の実装 を書いたときにはまだ API Version 3 は Subscriptions(定期課金) に対応していなかったのですが、2/14 から対応しました。



version 3 の API の基本は上記のエントリ及び Implementing In-app Billing (IAB Version 3) を見てください。
version 3 の subscriptions の購入フローはプロダクト購入フローとほぼ同じなので、上記のエントリを先にみることをオススメします。

Implementing Subscriptions

Subscription の購入フローもプロダクト購入フローとほぼ同じで、違う点は product type が "subs" である点です。購入結果は Activity の onActivityResult メソッドで受けとります(in-app products と同じ)。
  1. Bundle bundle = mService.getBuyIntent(3"com.example.myapp", MY_SKU, "subs", developerPayload);  
  2.   
  3. PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);  
  4.   
  5. if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {  
  6.    // Start purchase flow (this brings up the Google Play UI).  
  7.    // Result will be delivered through onActivityResult().  
  8.    startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));  
  9. }  
有効な subscriptions を問い合わせるには、product type に "subs" を指定して getPurchases メソッドを使います。
  1. Bundle activeSubs = mService.getPurchases(3"com.example.myapp""subs", continueToken);  
戻り値の Bundle はユーザーがオーナーの全ての有効な subscriptions(期限が切れていない subscriptions)を返します。更新せずに subscription の期限が切れると、戻り値の Bundle には含まれなくなります。


0 件のコメント:

コメントを投稿