Get text from advanced notification in status bar?

Is it possible to get text in an expanded notification in statusbar

? This means that the text sets mine Notification.BitTextStyle.bigText()

, for example, in an email notification from Gmail.

I would like to get it using Notification.extras, but there seems to be no constant, for example Notification.EXTRA_BIG_TEXT

, that allows this to work.

Is there any other way to get this text? Also, when I use

String bigtitle = mExtras.getString (Notification.EXTRA_TITLE_BIG;

it returns null

, any idea why? I am using this to receive an email message ( Testing the new Gmail notification shortcuts

β†’ see link below).

Below is an example of an extended Gmail notification: (I want to receive the following text ->

Now you get keyboard shortcuts for reply and archive inside ...

Gmail notification image (Can't post photos with less than 10 rep, sorry)

Alternatively, I've also tried the following:

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());

      

But that didn't work for me either, never got any text out of any of the views.

Update:

When I use the following code to get the text from the notification ...:

body = mExtras.getString(Notification.EXTRA_TEXT);

      

... everything works well until this is a Gmail / email notification:

As soon as I receive a Gmail notification, I receive the following error message:

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)

      

If I try to solve this problem by changing it to this ...

body = mExtras.getString(Notification.EXTRA_TEXT).toString();

      

... I get NullPointerException

It would be really nice if someone could help me here.

Thanks, REG1

+3


source to share


2 answers


Ok, so with this new information, I would try something like this:

SpannableString bigText = (SpannableString) mExtras.get(Notification.EXTRA_TEXT);
if(bigText != null){
    body = bigText.toString();
}

      



Edit: After researching the source, I would try the following:

CharSequence bigText = (CharSequence) mExtras.getCharSequence(Notification.EXTRA_TEXT);
if(bigText != null){
    body = bigText.toString();
}

      

+10


source


When any alert generates a Large Style Notice , the extended text can be retrieved using the key android.bigText

:



if(mExtras.getCharSequence("android.bigText")) {
    String body = mExtras.getCharSequence("android.bigText");
}

      

+1


source







All Articles