我在我的Android应用程序中使用百度推送服务。它在棒棒糖版本中工作正常。当我在带有棒棒糖版本的设备中运行应用程序时,它会崩溃。我正在收到以下崩溃日志。
02-03 11:55:39.772: E/AndroidRuntime(17430): java.lang.RuntimeException: Unable to create application com.sample.myapp: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.baidu.android.pushservice.action.PUSH_SERVICE (has extras) }
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4521)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ActivityThread.access$1500(ActivityThread.java:144)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.os.Handler.dispatchMessage(Handler.java:102)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.os.Looper.loop(Looper.java:135)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ActivityThread.main(ActivityThread.java:5221)
02-03 11:55:39.772: E/AndroidRuntime(17430): at java.lang.reflect.Method.invoke(Native Method)
02-03 11:55:39.772: E/AndroidRuntime(17430): at java.lang.reflect.Method.invoke(Method.java:372)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-03 11:55:39.772: E/AndroidRuntime(17430): Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.baidu.android.pushservice.action.PUSH_SERVICE (has extras) }
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1703)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ContextImpl.startService(ContextImpl.java:1687)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.content.ContextWrapper.startService(ContextWrapper.java:515)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.util.q.i(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.util.q.l(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.internal.PushManager.startWork(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.apiproxy.BridgePushManager.startWork(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.PushManager$40.run(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.LoadExecutor.excuteMethod(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.baidu.android.pushservice.PushManager.startWork(Unknown Source)
02-03 11:55:39.772: E/AndroidRuntime(17430): at com.sample.myapp.onCreate(HUSApp.java:62)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
02-03 11:55:39.772: E/AndroidRuntime(17430): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518)
02-03 11:55:39.772: E/AndroidRuntime(17430): ... 9 more
以下是抛出异常的代码
PushManager
.startWork(getApplicationContext(),
PushConstants.LOGIN_TYPE_API_KEY, BaiduUtils
.getMetaValue(getApplicationContext(),
"api_key"));
答案 0 :(得分:0)
从Android 5开始,必须始终使用显式意图调用bindService()。请参阅此答案:https://stackoverflow.com/a/28151732/3060087
您应该将启动PushService的意图更改为显式(提及包和服务名称)而不是隐式(仅将操作提及为意图过滤器)。
另一种选择是使用Android v19或更低版本作为目标。
答案 1 :(得分:-1)
旧的百度-Frontia-Full-Debug-2.0.6.jar更新到pushservice-5.6.0.30.jar 系统遇到此错误,可以删除Frontia相关类,结束此错误。 http://developer.baidu.com/announcement/89