B4A Library Notification Builder Library.

Eduard

Active Member
Licensed User
Longtime User

What can say? THANK YOU!

This is just what I need. I'll use it.
 

barx

Well-Known Member
Licensed User
Longtime User

I'm glad you like the library. As for the small icon, this will be the default (and only) behavior The android system takes care of these layouts and the end user has no control of them. My personal device only runs 4.0.3 so I haven't actually seen any expanding notifications from other apps. All my tests and screenshots were done on my wife sgs3 and she doesn't have any apps yet that use them either.
 

Inman

Well-Known Member
Licensed User
Longtime User
Does using SetParentActivity result in the clearing of Tag value? I could access the tag using StartingIntent's "Notification_Tag" extra value, but once I set the ParentActivity, I am getting empty value for Notification_Tag.
 

PhillipMorris

Member
Licensed User
Longtime User
Hello,
When I try to compile my project I get this error :
B4X:
Parsing code.                           0.01
Compiling code.                         0.04
Compiling layouts code.                 0.00
Generating R file.                      0.26
Compiling generated Java code.          Error
B4A line: 52
nb.SetStyle(nbBigTextStyle)
javac 1.7.0_07
src\Call\Logger\phev.java:228: error: cannot find symbol
_nb.SetStyle((android.support.v4.app.NotificationCompat.Style)(_nbbigtextstyle.getObject()));
                                                       ^
  symbol:   class Style
  location: class NotificationCompat
1 error

Here is the code I am using :
B4X:
   nb.SmallIcon = "icon"
   nb.Ticker = "Ticker"
   nb.ContentTitle = "Title"
   nb.ContentText = "Text"
   nb.ContentInfo = "Info"
   nb.SubText = "SubText"
   nb.OnGoingEvent = True
   nb.AddAction("icon","Wait","Tag",Main)
   nbBigTextStyle.Initialize
   nbBigTextStyle.BigText = "BigText"
   nbBigTextStyle.BigContentTitle = "Title"
   nbBigTextStyle.SummaryText = "Summary"
   
   nb.SetStyle(nbBigTextStyle)
   nb.Notify(1)
I copied android-support-v4.jar to libraries folder.
What am I doing wrong ?
 

barx

Well-Known Member
Licensed User
Longtime User


I have copied that code into a new project.

Added this as it is missing in the code above. Do you have this line elsewhere?
B4X:
nb.Initialize

I run the code and it runs fine. I have added the created project to this post for you to test and report back.

I would need to see more of your code to try and help any further.

Thanks
 

Attachments

  • nbtest.zip
    6 KB · Views: 918

barx

Well-Known Member
Licensed User
Longtime User
Does using SetParentActivity result in the clearing of Tag value? I could access the tag using StartingIntent's "Notification_Tag" extra value, but once I set the ParentActivity, I am getting empty value for Notification_Tag.

I'll look into it.

If I remember rightly I coded it to add the tag to the Intent used to add the parent activity to the stackbuilder, and remove the tag from the initial activity intent. If this is the case I will remove the 'remove' and upload.
 

Inman

Well-Known Member
Licensed User
Longtime User
Great.

Another issue I noticed is with AddAction. I set a tag in AddAction but in the Activity.GetStartingIntent, the value of HasExtra("Notification_Action_Tag") is always False. I am using the NotificationBigTextStyle. Could you please check it out?
 

PhillipMorris

Member
Licensed User
Longtime User
I tried the code that you sent me.

Same result :
B4X:
Parsing code.                           0.04
Compiling code.                         0.12
Compiling layouts code.                 0.01
Generating R file.                      0.34
Compiling generated Java code.          Error
B4A line: 47
nb.SetStyle(nbBigTextStyle)
javac 1.7.0_07
src\b4a\example\main.java:279: error: cannot find symbol
mostCurrent._nb.SetStyle((android.support.v4.app.NotificationCompat.Style)(mostCurrent._nbbigtextstyle.getObject()));
                                                                   ^
  symbol:   class Style
  location: class NotificationCompat
1 error

EDIT
Problem solved. I re-installed Android Support Library from SDK Manager. The code is running fine now.
Thanks for your help.

Another question.
Is it possible to refresh text added with nbInboxStyle.AddLine ?
 
Last edited:

Inman

Well-Known Member
Licensed User
Longtime User
Another question.
Is it possible to refresh text added with nbInboxStyle.AddLine ?

I haven't tried that style specifically but in other cases you can normally change the text in the same way you set the text the first time and then call Notify(id) with the same id as last time.
 

barx

Well-Known Member
Licensed User
Longtime User

you should be able to initialize the style again and then add all the required info for the style. Then call nb.SetStyle again adding the new style. Then call Notify again with the same ID as before.

Note: this is theoretical, i've no means of testing just yet.
 

barx

Well-Known Member
Licensed User
Longtime User

I'll add it to the testing and let you know what I come up with.
 

barx

Well-Known Member
Licensed User
Longtime User

Is it possible to show me some of your code, I have checked the add actions with the BogTextStyle on the Demo app and they seem to work fine. Have you referred to the Demo app to see if you code is similar?

Also to get the starting Intent the code in the demo app is

B4X:
Sub Service_Start (StartingIntent As Intent)
   'Dim In As Intent
   Dim intentExtra As String
   Log("Service Started")
   If StartingIntent.HasExtra("Notification_Action_Tag") Then
      Log("Extra Found")
      intentExtra = StartingIntent.GetExtra("Notification_Action_Tag")
      ToastMessageShow(intentExtra, False)
   End If
   StopService("")
End Sub

Though this uses a service, I will test with a activity.
 

barx

Well-Known Member
Licensed User
Longtime User
OK it appears that the Action Tag always defaults to the Title of the action. This is the behaviour if "" is passed for the action. Though even setting your own tag still seems to act this way. I don't really understand that as the java code behind essentially is

B4X:
if tag <> "" then
    PutExtra(Tag)
Else
    PutExtra(Title)
End if

I will need to look through, edit and test the library source. I currently don't have access to my dev machine. Will get onto it as soon as though.

Thanks for bringing this to my attention.

A temp workaround would be to look for tags match the Action Title.
 

gadgetmonster

Active Member
Licensed User
Longtime User
Hi Barx

I'm new to notifications so please forgive me if i'm not understanding something here.

What I am trying to achieve is an ongoing notification that when clicked opens up a certain activity in my app. This I have working

How can I tell if the notification is active or not? I need to know this so that in my settings screen I can show an option to cancel it if it is active or start it if its not.

Thanks for your help.
 

barx

Well-Known Member
Licensed User
Longtime User
The notification object doesn't provide such a method. You would have to keep track of this yourself. i.e. store a persistent Boolean value and set it whenever you call .Notify, .Cancel or your activity is called from the notification if you have it set to clear when clicked. This value could be saved in a database if your app uses one, in a file or using the state manager. I wouldn't just save it as a Process_Global variable as I believe the notification could live on if the process is killed and so value would be lost. I could be wrong though, maybe someone else could confirm this.
 

gadgetmonster

Active Member
Licensed User
Longtime User
Icon issue

Hi,

When I set my ongoing notification I use SmallIcon to set a different icon to the apps. I have noticed that when I install a new version of my app, whilst the notification is still available (I don't have to re-add it) the icon has gone back to the apps icon instead of the one I set using SmallIcon. Is there a way around this? I'm just worried that if a user downloads an update then their icon will change.
 

barx

Well-Known Member
Licensed User
Longtime User
Hi Paul,

I'm not fully understanding you scenario. How are you installing the new version? can you post your code relating to the notification?

cheers
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…