利用城市飞艇推送通知返回APID为空的第一次发射 [英] Push Notifications using Urban Airship returns apID as null at the first launch
问题描述
我已经成功地整合城市飞艇推送通知到我的android应用。我遇到了一个问题在这里,这是APID变成空的第一个启动,然后用第二次发射,APID来运行。
I have successfully integrated urban airship push notification to my android application. I ran into an issue here, that is the apID becomes null with the very first launch and then with the second launch, apId comes correctly.
这是我怎么抢APID:
This is how I grab the 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类。任何帮助是AP preciated。
I also have an IntentReceiver class. Any help is appreciated.
推荐答案
我发现原因是一个延迟,以获得APID,它需要一些时间,因此,在你的IntentReceiver类,你必须等待` PushManager.ACTION_REGISTRATION_FINISHED火。从那里,你可以得到APID:
I found out that the reason is a delay, to get the apId, it takes some time, therefore, in your IntentReceiver class, you have to wait for `PushManager.ACTION_REGISTRATION_FINISHED to fire. From there, you can get the apId:
if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {
Log.i(logTag,"Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID)+ ". Valid: "+ intent.getBooleanExtra( PushManager.EXTRA_REGISTRATION_VALID, false));
// Notify any app-specific listeners
String apid = PushManager.shared().getAPID();
Intent launch = new Intent(UAirship.getPackageName()+ APID_UPDATED_ACTION_SUFFIX);
UAirship.shared().getApplicationContext().sendBroadcast(launch);
}
这篇关于利用城市飞艇推送通知返回APID为空的第一次发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!