都市飛行船のプッシュ通知を Android アプリケーションに正常に統合しました。ここで問題が発生しました。つまり、最初の起動で apID が null になり、2 回目の起動で apId が正しく表示されます。
これは、apId を取得する方法です。
String apid = PushManager.shared().getAPID();
これは私が使用したクラスです:
public class MyApplication extends Application {
public static SharedPreferences PREFS_TOKEN;
public static final String PREFERENCE = "UrbanAirship";
public static String tokenKey;
@Override
public void onCreate(){
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
UAirship.takeOff(this, options);
PushManager.enablePush();
Logger.logLevel = Log.VERBOSE;
// use CustomPushNotificationBuilder to specify a custom layout
CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();
nb.statusBarIconDrawableId = R.drawable.paw;// custom status bar icon
nb.layout = R.layout.notification;
nb.layoutIconDrawableId = R.drawable.paw;// custom layout icon
nb.layoutIconId = R.id.icon;
nb.layoutSubjectId = R.id.subject;
nb.layoutMessageId = R.id.message;
// customize the sound played when a push is received
// nb.soundUri =
// Uri.parse("android.resource://"+this.getPackageName()+"/"
// +R.raw.cat);
String apid = PushManager.shared().getAPID();
Logger.info("My Application onCreate - App APID: " + apid);
PREFS_TOKEN = this.getSharedPreferences(PREFERENCE,
Context.MODE_PRIVATE);
Editor edit = PREFS_TOKEN.edit();
if (apid != null && apid != "") {
edit.putString(PREFERENCE, apid);
edit.commit();
} else {
edit.putString(PREFERENCE, apid);
edit.commit();
}
tokenKey = PREFS_TOKEN.getString(PREFERENCE, "");
System.out.println("---------- - App APID: " + tokenKey);
PushManager.shared().setNotificationBuilder(nb);
PushManager.shared().setIntentReceiver(IntentReceiver.class);
}
}
IntentReceiver クラスもあります。どんな助けでも大歓迎です。