Application.onCreate中的我的代码。该应用程序在UAirship.takeoff(this,options);
崩溃,请帮忙。
public class LiveVideoApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
// Optionally, customize your config at runtime:
//
options.inProduction = false;
options.developmentAppKey = "key.. ";
options.developmentAppSecret = "secret..";
UAirship.takeOff(this, options);
PushManager.shared().setIntentReceiver(IntentReceiver.class);
Logger.logLevel = Log.VERBOSE;
//use CustomPushNotificationBuilder to specify a custom layout
CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();
nb.statusBarIconDrawableId = R.drawable.icon_small;//custom status bar icon
//
nb.layout = R.layout.notification;
nb.layoutIconDrawableId = R.drawable.icon;//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);
PushManager.shared().setNotificationBuilder(nb);
PushManager.shared().setIntentReceiver(IntentReceiver.class);
}
}
异常日志:
03-15 00:25:37.106: E/AndroidRuntime(2920): FATAL EXCEPTION: main
03-15 00:25:37.106: E/AndroidRuntime(2920): java.lang.RuntimeException: Unable to create application com.LiveVideoApplication: java.lang.IllegalArgumentException: Application configuration is invalid.
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3275)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.ActivityThread.access$2200(ActivityThread.java:117)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.os.Looper.loop(Looper.java:123)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-15 00:25:37.106: E/AndroidRuntime(2920): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 00:25:37.106: E/AndroidRuntime(2920): at java.lang.reflect.Method.invoke(Method.java:507)
03-15 00:25:37.106: E/AndroidRuntime(2920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-15 00:25:37.106: E/AndroidRuntime(2920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-15 00:25:37.106: E/AndroidRuntime(2920): at dalvik.system.NativeStart.main(Native Method)
03-15 00:25:37.106: E/AndroidRuntime(2920): Caused by: java.lang.IllegalArgumentException: Application configuration is invalid.
03-15 00:25:37.106: E/AndroidRuntime(2920): at com.urbanairship.UAirship.takeOff(Unknown Source)
03-15 00:25:37.106: E/AndroidRuntime(2920): at com.LiveVideoApplication.onCreate(LiveVideoApplication.java:27)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
03-15 00:25:37.106: E/AndroidRuntime(2920): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3272)
答案 0 :(得分:5)
我也遇到过这个问题,我解决了。我建议您确保在UrbanAirship上使用与您的应用程序相同的应用程序包创建了一个应用程序。并且确保您的密钥和秘密是正确的。
developmentAppKey和developmentAppSecret错误时会抛出 IllegalArgumentException
。
答案 1 :(得分:5)
需要注意的一点是,如果您使用 airshipconfig.properties 文件,并将其放在与 project.properties 文件相同的目录级别, Urban Airship代码将无法找到它,并且对 AirshipConfigOptions.loadDefaultOptions(this)的调用将返回空字符串值。
这也可能导致您看到的异常。
在这种情况下,解决方案是将 airshipconfig.properties 文件放在项目的资产目录中。
答案 2 :(得分:1)
如果您检查了所有其他建议,但仍然收到IllegalArgumentException,则当手机没有任何关联的Google帐户时,也会抛出此异常。
如果是这种情况,您应该能够登录/关联Google帐户,然后您必须重新启动手机。
我建议在一个try catch中包装Urban Airship初始化调用,以阻止它在这种情况下使用应用程序!如果您使用错误报告,最好将其记录为已处理的异常,以便您知道它是否以及何时发生。