java.lang.NoSuchMethodError: android.service.notification.StatusBarNotification.getKey
Posted
技术标签:
【中文标题】java.lang.NoSuchMethodError: android.service.notification.StatusBarNotification.getKey【英文标题】: 【发布时间】:2014-11-03 19:30:50 【问题描述】:我有一个扩展 NotificationListenerService 的服务。在onNotificationPosted 方法中,我试图从正在接收的StatusBarNotification 对象中获取getKey() 函数。
所有其他功能都可以工作,但是当我执行 sbn.getKey() 时,我得到以下错误(下面的 logCat 输出)。 API 是否记录不正确?
这是在 android API 级别 18 (4.3) 中
public void onNotificationPosted(StatusBarNotification sbn)
Log.v(TAG, "********** onNotificationPosted, in NLService.java");
Log.v(TAG,
"ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText
+ "\t" + sbn.getPackageName());
Log.v(Constants.TAG_ALL, "------------------------- sbn.getId() = "
+ String.valueOf(sbn.getId()));
Log.v(Constants.TAG_ALL, "------------------------- sbn.getKey() = "
+ sbn.getKey());
Log.v(Constants.TAG_ALL,
"------------------------- sbn.getPackageName() = "
+ sbn.getPackageName());
Log.v(Constants.TAG_ALL,
"------------------------- sbn.getPostTime() = "
+ String.valueOf(sbn.getPostTime()));
Log.v(Constants.TAG_ALL, "------------------------- sbn.getUserId() = "
+ String.valueOf(sbn.getUserId()));
Log.v(Constants.TAG_ALL,
"------------------------- sbn.isClearable() = "
+ String.valueOf(sbn.isClearable()));
Log.v(Constants.TAG_ALL, "------------------------- sbn.toString() = "
+ String.valueOf(sbn.toString()));
LogCat 输出:
09-10 03:13:44.588: E/JavaBinder(7329): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
09-10 03:13:44.588: E/JavaBinder(7329): java.lang.NoSuchMethodError: android.service.notification.StatusBarNotification.getKey
09-10 03:13:44.588: E/JavaBinder(7329): at com.mavdev.focusoutfacebook.notifications.NLService.onNotificationPosted(NLService.java:133)
09-10 03:13:44.588: E/JavaBinder(7329): at android.service.notification.NotificationListenerService$INotificationListenerWrapper.onNotificationP osted(NotificationListenerService.java:167)
09-10 03:13:44.588: E/JavaBinder(7329): at android.service.notification.INotificationListener$Stub.onTransact(INotificationListener.java:56)
09-10 03:13:44.588: E/JavaBinder(7329): at android.os.Binder.execTransact(Binder.java:388)
09-10 03:13:44.588: E/JavaBinder(7329): at dalvik.system.NativeStart.run(Native Method)
09-10 03:13:44.588: W/dalvikvm(7329): threadid=9: thread exiting with uncaught exception (group=0xa4c09648)
09-10 03:13:44.588: E/AndroidRuntime(7329): FATAL EXCEPTION: Binder_2
09-10 03:13:44.588: E/AndroidRuntime(7329):
09-10 03:13:44.588: E/AndroidRuntime(7329): at com.mavdev.focusoutfacebook.notifications.NLService.onNotificationPosted(NLService.java:133)
09-10 03:13:44.588: E/AndroidRuntime(7329): at android.service.notification.NotificationListenerService$INotificationListenerWrapper.onNotificationPosted(NotificationListenerService.java:167)
09-10 03:13:44.588: E/AndroidRuntime(7329): at android.service.notification.INotificationListener$Stub.onTransact(INotificationListener.java:56)
09-10 03:13:44.588: E/AndroidRuntime(7329): at android.os.Binder.execTransact(Binder.java:388)
09-10 03:13:44.588: E/AndroidRuntime(7329): at dalvik.system.NativeStart.run(Native Method)
【问题讨论】:
【参考方案1】:#getKey() 方法是在 API 级别 20 中添加的,因此您不能在 API 级别 18 中使用它。
请参阅顶部的documentation,说明所需的 API 级别。
【讨论】:
谢谢,我没注意到。将标记为答案。以上是关于java.lang.NoSuchMethodError: android.service.notification.StatusBarNotification.getKey的主要内容,如果未能解决你的问题,请参考以下文章