我正在尝试将一组StatusBarNotifications发送给我的另一个服务,所以我这样做了:
扩展的服务NotificationListenerService:
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
// TODO Auto-generated method stub
StatusBarNotification[] activeN = super.getActiveNotifications();
Intent i = new Intent(this, CoreTwo.class);
i.putExtra("activenotifications", activeN);
startService(i);
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个关于文件描述符的RuntimeException.
我只找到几个环节解决这一问题,例如这一个在这里.答案提到了以下内容:
使用Bundle.putBinder()传递一个Binder,它将使用ParcelFileDescriptor(来自API 18)返回一个Parcel.但我不明白如何实现这一点.
此链接中的另一个人在这里提到以下内容:
如果我从ContentProvider返回PaecelFileDescriptor,它可以正常工作.
但我不明白他的意思.
最后一个环节是这个位置.它解决了与我相同的问题,但似乎没有解决方案.
有人理解我链接的这些潜在解决方案吗?是否有针对此问题的解决方法,可能是另一种发送数据的方式(StatusBarNotification [](它扩展了Parcelable))?
这是日志:
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): Error running onNotificationPosted
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): java.lang.RuntimeException: Not allowed to write file descriptors here
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.nativeAppendFrom(Native Method)
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.appendFrom(Parcel.java:431)
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Bundle.writeToParcel(Bundle.java:1679)
08-23 …Run Code Online (Sandbox Code Playgroud) 是否可以在扩展通知中获取文本statusbar?这意味着文字设置了我Notification.BitTextStyle.bigText(),例如来自Gmail的电子邮件通知.
我想使用Notification.extras来获取它,但似乎没有常量,Notification.EXTRA_BIG_TEXT例如,允许它工作.
是否有另一种获取此文本的方法?当我使用时
String bigTitle = mExtras.getString(Notification.EXTRA_TITLE_BIG;
它回来了null,任何想法为什么?我用它来获取电子邮件的主题(Testing the new Gmail notification shortcuts- >见下面的链接).
以下是扩展Gmail通知的示例:(我想获得以下文字 - >
您现在可以获得回复和存档的快捷按钮...
Gmail通知的图片 (无法发布信誉低于10的图片,抱歉)
作为替代方案,我也尝试了以下方法:
RemoteViews rv = mNotification.contentView;
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup localView = (ViewGroup) inflater.inflate(rv.getLayoutId(), null);
rv.reapply(getApplicationContext(), localView);
everything = new StringBuilder(150);
for(int i=0; i<((ViewGroup)localView).getChildCount(); ++i) {
View nextChild = ((ViewGroup)localView).getChildAt(i);
try{
TextView tv = (TextView) localView.findViewById(nextChild.getId());
everything.append(tv.getText().toString());
}catch(Exception e){
continue;
}
}
Log.i("abc", everything.toString());
Run Code Online (Sandbox Code Playgroud)
但这对我来说也不起作用,似乎从来没有从任何观点中得到任何文本.
更新:
当我使用以下代码从通知中获取文本时...:
body = mExtras.getString(Notification.EXTRA_TEXT); …Run Code Online (Sandbox Code Playgroud) notifications android android-notifications android-notification-bar
android ×2