【Android】Android用のレビューダイアログ作成用のヘルパーライブラリをオープンソースとして公開します

この記事の概要

RMP-AppiraterKit screenshot

Android用のレビューダイアログ作成用のヘルパーライブラリをオープンソースとして公開しました。実はこのライブラリは半年前に公開していたのですが、いくつか引き合いがあったためにこのたびブログ記事にしました。

We published RMP-AppiraterKit by open source.
RMP-AppiraterKit is an Android library to create your customaizable user review dialog. It will help remind users to review your app on the Google play.

はじめに

以前オープンソースとして公開したAndroid用のレビューダイアログライブラリRMP-Appiraterはダイアログの表示条件をカスタムできるという特徴を持つAndroid用のレビューダイアログライブラリです。

RMP-Appiraterは簡単に使える反面、ダイアログの内容のカスタマイズ性が低いため、『レビューダイアログ中に、お問い合わせフォームに飛ばすボタンも同じダイアログに置きたい』なんてことがしたくなった場合にRMP-Appiraterでは対応できませんでした。
そんなわけで、ダイアログの表示条件とともにダイアログの内容のカスタムもできるライブラリRMP-AppiraterKitを作成しました。

使い方

Githubのサイトからダウンロードした上でAndroid Studioにモジュールをインポートしていただくか、Mavenからダウンロードできます。


アプリ起動時に呼ばれるActivityの Activity#onCreate ( Bundle ) あたりに下記のコードを入れます。

public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // RmpAppiraterKitにアプリの起動を通知する
        AppiraterMeasure.appLaunched(this);
    }
}

評価ダイアログを表示するのは、下記のようなコードになります。

private void showDialog() {
    final SharedPreferences prefs = getSharedPreferences("Settings", Context.MODE_PRIVATE);
    // 最後に AppiraterMeasure#appLaunched(android.content.Context) を呼んだ際に
    AppiraterMeasure.Result appiraterResult = AppiraterMeasure.getLastAppLaunchedResult();
    if (
        // "このアプリを評価する"ボタンをまだ押していないか、
        !prefs.getBoolean(PREF_KEY_APP_ALREADY_RATE, false) ||
        // 以前にアプリを起動した時からバージョンアップなどでアプリケーションのバージョンが変わった
        (appiraterResult != null &&
                appiraterResult.getAppVersionCode() != appiraterResult.getPreviousAppVersionCode())) {
        // レビューダイアログを生成する
        AppiraterDialogBuilder builder = new AppiraterDialogBuilder(this);
        builder
                // ダイアログのタイトル
                .setTitle("このアプリを評価してください")
                // ダイアログのメッセージ
                .setMessage("このアプリの評価をお願いします!")
                // ストアのアプリページに遷移するボタン
                .addButton("★5をつける", new AppiraterDialogBuilder.OnClickListener() {
                    @Override
                    public void onClick(Dialog dialog) {
                        SharedPreferences.Editor prefsEditor = prefs.edit();
                        prefsEditor.putBoolean(PREF_KEY_APP_ALREADY_RATE, true);
                        prefsEditor.apply();
                        AppiraterUtils.launchStrore(MainActivity.this);
                        dialog.dismiss();
                    }
                })
                // お問い合わせサイトに遷移するボタン
                .addButton("問題を報告する", new AppiraterDialogBuilder.OnClickListener() {
                    @Override
                    public void onClick(Dialog dialog) {
                        Uri uri = Uri.parse("http://www.google.com/"); // Inputs your supports site.
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                        dialog.dismiss();
                    }
                })
                // ダイアログを閉じるボタン
                .addButton("あとで", new AppiraterDialogBuilder.OnClickListener() {
                    @Override
                    public void onClick(Dialog dialog) {
                        dialog.dismiss();
                    }
                });
        Dialog dialog = builder.create();
        dialog.show();
    } else {
        // "★5をつける"をすでに押しており、かつこのバージョンを過去に立ち上げているため何もしない
    }
}

上記の例ではRMP-AppiraterKitのダイアログを使っていますが、もちろん自作のダイアログも使用可能です。
また AppiraterMeasure.getLastAppLaunchedResult() を呼ぶと

  • アプリの起動回数
  • アプリの現在のバージョンの起動回数
  • 初回起動日時
  • 以前にアプリを起動した時からバージョンアップなどでアプリケーションのバージョンが変わったか

を取得できるので、レビューダイアログ表示用途の他にもユーザの簡単な行動履歴情報の追跡にも使えたりします。

RMP-AppiraterとRMP-AppiraterKitのどちらを使うべきか

アプリの起動時に固定のレビューダイアログが表示できればいいだけならはRMP-Appiraterを、それ以上のことをするのならRMP-AppiraterKitを使うのがよいでしょう。

ライセンス

Apache License, Version 2.0のライセンスになります。

Copyright (C) 2015 Recruit Marketing Partners Co.,Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

さいごに

不具合修正や改良等ありましたら、リポジトリにどしどしプルリクエストいただけると嬉しいです。