REG*_*EG1 4 notifications android android-notifications android-notification-bar
是否可以在扩展通知中获取文本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)
...只要不是Gmail /电子邮件通知,一切正常:
收到Gmail通知后,我收到以下错误消息:
08-19 20:19:37.379: W/Bundle(6646): Key android.text expected String but value was a android.text.SpannableString. The default value <null> was returned.
08-19 20:19:37.379: W/Bundle(6646): Attempt to cast generated internal exception:
08-19 20:19:37.379: W/Bundle(6646): java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
08-19 20:19:37.379: W/Bundle(6646): at android.os.Bundle.getString(Bundle.java:1121)
08-19 20:19:37.379: W/Bundle(6646): at com.myprojectabc.storage.Core$mainmethod$1.run(Core.java:394)
08-19 20:19:37.379: W/Bundle(6646): at android.os.Handler.handleCallback(Handler.java:733)
08-19 20:19:37.379: W/Bundle(6646): at android.os.Handler.dispatchMessage(Handler.java:95)
08-19 20:19:37.379: W/Bundle(6646): at android.os.Looper.loop(Looper.java:136)
08-19 20:19:37.379: W/Bundle(6646): at android.app.ActivityThread.main(ActivityThread.java:5001)
08-19 20:19:37.379: W/Bundle(6646): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 20:19:37.379: W/Bundle(6646): at java.lang.reflect.Method.invoke(Method.java:515)
08-19 20:19:37.379: W/Bundle(6646): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-19 20:19:37.379: W/Bundle(6646): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-19 20:19:37.379: W/Bundle(6646): at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
如果我然后通过将其更改为此来尝试解决该问题...
body = mExtras.getString(Notification.EXTRA_TEXT).toString();
Run Code Online (Sandbox Code Playgroud)
......我得到了 NullPointerException
如果有人能帮助我,我真的很感激
谢谢,REG1
Lar*_*zie 11
好的,有了这个新信息,我会尝试这样的事情:
SpannableString bigText = (SpannableString) mExtras.get(Notification.EXTRA_TEXT);
if(bigText != null){
body = bigText.toString();
}
Run Code Online (Sandbox Code Playgroud)
编辑:在查看源代码后,我会尝试这样做:
CharSequence bigText = (CharSequence) mExtras.getCharSequence(Notification.EXTRA_TEXT);
if(bigText != null){
body = bigText.toString();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2304 次 |
| 最近记录: |