Problem with Notification tag!? Help!

peve9

Member
Licensed User
Longtime User
Hi everyone,
I have a problem with notification tag.

In Sub button1_Click I create the notification using the NotificationBuilder library

B4X:
Dim n As NotificationBuilder
n.Initialize
n.LargeIcon=LoadBitmap(File.DirAssets,"icon2.png")
n.AddAction("icon","title","test",Main1)
n.setParentActivity(Main)
n.AutoCancel=True
n.setActivity(Main1)
n.Tag="ciao"
n.SmallIcon="icon"
n.OnGoingEvent=True
n.Notify(1)

And in the Activity_Resume of Main1 I have

B4X:
Dim In As Intent
Dim intentExtra As String
In = Activity.GetStartingIntent
If In.HasExtra("Notification_Tag") Then
      intentExtra = In.GetExtra("Notification_Tag")
End If
Log(intentExtra)

but intentExtra is always empty..
WHY??

Thanks to all!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not familiar with the implementation of NotificationBuilder library. My guess is that it doesn't add this tag like the regular Notification object does.

@barx, This is the relevant Java code in Notification object:
B4X:
   public void SetInfo2(BA ba, String Title, String Body, String Tag, Object Activity) throws ClassNotFoundException {
      getObject().when = System.currentTimeMillis();
      Intent i = Common.getComponentIntent(ba, Activity);
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
      if (Tag != null)
         i.putExtra("Notification_Tag", Tag);
      PendingIntent pi = PendingIntent.getActivity(ba.context, Tag == null ? 0 : pendingId++
            , i,
            PendingIntent.FLAG_UPDATE_CURRENT);
      getObject().setLatestEventInfo(ba.context, Title, Body, pi);
   }
 
Upvote 0

peve9

Member
Licensed User
Longtime User
I have a problem when I display the notification, because I have to intercept a text that is unique for that notification (notification generated in a code module), and pass this text into another module.

How can I do it?:confused:

:sign0085: THANKS ALL!
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
@peve9,
This is an issue only when using SetParentActivity. If you remove that then you should get the tag. Also, read below.

@Erel I do something very similar in this lib with:

B4X:
      if (nTag != null) {
         resultIntent.putExtra("Notification_Tag", nTag);         
      }   
      
      if (pActivity != null) {
            Intent parentIntent = Common.getComponentIntent(ba, pActivity);
            if (nTag != null) {
               parentIntent.putExtra("Notification_Tag", nTag);   
               resultIntent.removeExtra("Notification_Tag");
            }
            stackBuilder.addNextIntent(parentIntent);   
      }

For some reason I included the action of removing the extra from the first intent when setting the parent. Like a fool I didn't make notes on this section of code and cannot for the life of me remember why I did that. Another user reported the same issue, I have edited out the line but have not had time to test it. And probably wont for a bit (bad support me :sign0161:)

I will update the library with the edit and the users can test if they wish.
 
Upvote 0
Top