
我想使用Notification.extras来获取它,但似乎没有常量,例如Notification.EXTRA_BIG_TEXT,它允许这个工作.
是否有另一种获取此文本的方法?
当我使用时
String bigTitle = mExtras.getString(Notification.EXTRA_Title_BIG;
它返回null,任何想法为什么?我用它来获取电子邮件的主题(测试新的Gmail通知快捷方式 – >请参阅下面的链接).
以下是扩展Gmail通知的示例:(我想获得以下文字 – >
You Now get shortcut buttons for Reply and Archive within…
Picture of Gmail Notification
(不能发布信誉低于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()); 但这对我来说也不起作用,似乎从来没有从任何观点中得到任何文本.
更新:
当我使用以下代码从通知中获取文本时…:
body = mExtras.getString(Notification.EXTRA_TEXT);
…只要不是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.String08-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.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)
如果我然后通过将其更改为此来尝试解决该问题…
body = mExtras.getString(Notification.EXTRA_TEXT).toString();
…我得到一个NullPointerException
如果有人能帮助我,我真的很感激
谢谢,REG1
解决方法 好的,有了这个新信息,我会尝试这样的事情:SpannableString bigText = (SpannableString) mExtras.get(Notification.EXTRA_TEXT);if(bigText != null){ body = bigText.toString();} 编辑:
在查看源代码后,我会尝试这样做:
CharSequence bigText = (CharSequence) mExtras.getCharSequence(Notification.EXTRA_TEXT);if(bigText != null){ body = bigText.toString();} 总结 以上是内存溢出为你收集整理的android – 从状态栏中的扩展通知中获取文本?全部内容,希望文章能够帮你解决android – 从状态栏中的扩展通知中获取文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)