AndroidにOpenFeintを組み込んでみよう 2

きっとスクリーンショットとかあると解説が分かりやすいんだろうな、とか
そういうところに気配りをしているサイトがモテるサイトなんだろうな、と
思っている昨今ですが、改善せずに文字だけで書いて行きます。


大抵はOpenFeintSDKフォルダ内にあるREADME.htmlの
「OpenFeint Android Quick Start Guide」、「4.Integrate OpenFeint into your game」
に書いてある内容の翻訳「みたいな」ものになります。


SDKのビルドについては、「Import」からワークスペースに読み込んで、
プロジェクトの「Property」の「Android」から「Is Library」にチェックを入れてビルドして
ゲームを作ってるプロジェクトの「Property」の「Android」から、「Library」を選択して
表示されているはずの「OpenFeintAPI」を設定するだけです。


◆ Manifestファイルの編集
・AndroidManifest.xml tag内に以下の文言を入れます。

<activity android:name="com.openfeint.internal.ui.IntroFlow"
              android:label="IntroFlow"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar"/>
<activity android:name="com.openfeint.api.ui.Dashboard"
              android:label="Dashboard"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar"/>
<activity android:name="com.openfeint.internal.ui.Settings"
              android:label="Settings"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar"/>
<activity android:name="com.openfeint.internal.ui.NativeBrowser"
              android:label="NativeBrowser"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar"/>


・AndroidManifest.xmlにpermissionの設定を追加します。

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

最初の2つは、インターネットアクセスのために必要です。
SDカードアクセスのpermissionについては、ここに状態保存することで動作が
軽快になるぜ!みたいなもので、
GET_ACCOUNTSについてはPhoneSDKが「5」以上、つまりはAndroid2.0以降ならばこれを取得する
ことでE-mailアドレスを勝手に検索してくれるので個別認証が簡単になるってことらしい。


◆ Applicationの設定
Applicationをextendsしたクラスを作って、Applicationの起動時にOpenFeintへの
ログインを要求する形にします。
これはまぁ、サンプルソースに「OpenFeintApplication.java」があるのでこれをそのまま
パクって来るのが簡単かと思います。


gameName〜gameSecretには使いたいアプリケーションの情報をOpenFeintのページにある
「Application Information」から参照して、指定してあげてください。


取り合えずこれで初期設定は終わりかな?


後はまぁ、続いて「5. Add OpenFeint features to your game」を見れば大体分かるはずです。
その他、サンプルなどから読み取って使った便利な関数を適当に列記しておきます。

・OpenFeint.isUserLoggedIn()
 ログイン中ならば「true」が返って来ます。

・Dashboard.openLeaderboards();
 Leaderboardの一覧を開きます。

・OpenFeintInternal.getInstance().login(boolean spotlight);
 ログイン画面を表示します。

・OpenFeintInternal.getInstance().logoutUser(null);
 ログアウトさせます。

・Dashboard.openLeaderboard(String leaderboardID);
 指定したIDのランキングを表示します。

取り合えずこれだけ覚えておけば、簡単に組み込めると思います。
まさか1日もかからずに組み込み終わると思わなかった。