能否在状态栏中获取扩展通知中的文本?这意味着可以获取通过
我想使用Notification.extras获取它,但似乎没有常量,例如
还有其他方法可以获取此文本吗? 此外,当我使用
下面是扩展Gmail通知的示例:(我想要获取以下文本 ->
作为替代方案,我还尝试了以下内容:
如果我试图通过将问题更改为以下内容来解决它...
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());
但这对我也没用,似乎从任何视图中都无法获取到任何文本。
更新:
当我使用以下代码从通知中获取文本时……:
body = mExtras.getString(Notification.EXTRA_TEXT);
只要不是Gmail/Email通知,一切都很正常:
一旦我收到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)
如果我试图通过将问题更改为以下内容来解决它...
body = mExtras.getString(Notification.EXTRA_TEXT).toString();
当我运行代码时,出现了NullPointerException
的错误。
非常感谢有人能够帮助我解决这个问题。
谢谢,REG1