Googleが開発者向けのガイドがあります。
http://developer.android.com/google/play/billing/billing_integrate.html
今回は英語が苦手な方に簡単な実装方法を伝授してゆきます。
大まかな手順
- 1. プロジェクトに In-app Billing ライブラリを追加する
- 2. AndroidManifest.xml を変更する
- 3. ServiceConnection を作成し、IInAppBillingService にバインドする
- 4. アプリから In-app Billing リクエストを IInAppBillingService に送る
- 5. Google Play からの In-app Billing レスポンスを処理する
「プロジェクトにIn-app Billingライブラリを追加する。」
まず最初にEclipse➡Window➡Android SDK Managerへ
こちらのGoogle Play Billing Library をインストール
[sdk-install-dir]/extras/google/play_billing/in-app-billing-v03/samples/TrivialDrive/ こちらのファイルパスにサンプルのプロジェクトがあります。
とりあえずインポート
そして、Runしてみてください。
落ちます。
理由:公開鍵を設定をしていないから
GoogleConsoleでアプリの設定をしてください。
必要なのはパッケージネームと公開鍵!
公開鍵はsrc/MainActivity.javaの
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// load game data
loadData();
/* base64EncodedPublicKey should be YOUR APPLICATION’S PUBLIC KEY
* (that you got from the Google Play developer console). This is not your
* developer public key, it’s the *app-specific* public key.
*
* Instead of just storing the entire literal string here embedded in the
* program, construct the key at runtime from pieces or
* use bit manipulation (for example, XOR with some other string) to hide
* the actual key. The key itself is not secret information, but we don’t
* want to make it easy for an attacker to replace the public key with one
* of their own and then fake messages from the server.
*/
String base64EncodedPublicKey = “CONSTRUCT_YOUR_KEY_AND_PLACE_IT_HERE”;
CONSTRUCT_YOUR_KEY_AND_PLACE_IT_HEREに公開鍵を入れてあげてください。(長いですけど
んで、ひとまずビルドしてRunすると落ちていた部分が解消されているはず、もし落ちる場合はapkをGoogle consoleに登録(入れておく必要があります。)