SDKの導入: Android
このページはLogBase Android SDK バージョン 4.0.0 以上の導入手順になります。 LogBase Android SDK バージョン 3.1.1 以前を利用する場合は こちら を参照してください。
LogBase Android SDK を利用するには Android Gradle plugin のバージョンが 2.3.0 以上である必要があります。
app/build.gradle の変更
LogBase Android SDK の手順に従い app/build.gradle
を変更します。
logbase.xml を追加
ファイルapp/src/main/res/values/logbase.xml
を追加し、次の内容をlogbase.xml
に追加します。
YOUR_APPLICATION_ID
とYOUR_APPLICATION_SECRET_KEY
は、LogBase管理画面の「設定」→「導入手順」に記載されているアプリIDとシークレットキーにそれぞれ置き換えてください。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="logbase_application_id" translatable="false">YOUR_APPLICATION_ID</string>
<string name="logbase_secret_key" translatable="false">YOUR_APPLICATION_SECRET_KEY</string>
</resources>
SDK の初期化
アプリを開始して最初に起動されるActivity
のonCreate()
で初期化します。また、onNewIntent()
でLogPush#onNewIntent()
を呼び出します。
import net.p_lucky.logbase.init.LogBaseInitializer;
import net.p_lucky.logbase.init.LogBaseParams;
import net.p_lucky.logbase.init.LogBaseServices;
public class MainActivity extends AppCompatActivity {
LogBaseServices services;
@Override
public void onCreate(Bundle savedInstanceState) {
// ...
// 初期化
services = LogBaseInitializer.initialize(this);
// ...
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
services.logPush().onNewIntent(intent);
}
}
Google Play開発者サービスの必要性
アプリをインストールしたユーザの端末が下記の場合、LogBase によるプッシュ通知の配信が行えません。
- Google Play開発者サービスがインストールされていない
- インストールされているGoogle Play開発者サービスのバージョンが古い
確実にユーザへプッシュ通知を配信したい場合には、Google Play開発者サービスのインストールないし更新を促すメッセージを端末のユーザに表示しましょう。
Android.Intent.Category.LAUNCHER を指定した<activity>が複数ある場合
通知をタップしたときに起動するActivityは、AndroidManifest.xmlで最も上に書かれたものになります。
また、アプリのユーザが AndroidManifest.xml で最も上に書かれたもの以外のandroid.intent.category.LAUNCHERを指定した<activity>からアプリを起動した際にはLogBaseのデバイス登録やタグ付けなどが行われない可能性があります。