B4A Library Notification Builder Library.

CryoGenID

Active Member
Licensed User
Longtime User
Thanks a lot for your reply

Somehow Android Wear doesn't like me :-(

The only thing I got working was to send a text message with the default b4a icon to the watch...
When I try to send another icon, I still get the "original" icon on the watch (on the tablet, I get the correct "new" icon in the notification):
B4X:
Dim nb As NotificationBuilder
    Dim wearableExtender As NotificationWearableExtender
    nb.Initialize
    wearableExtender.Initialize
   
    nb.SmallIcon = "mam1"
    nb.ContentTitle = "Some Title 2"
    nb.ContentText = "Some Text 2"
    nb.Extend(wearableExtender)
    nb.Notify(1)

Do you know why that is happening? Using your demo application I get your custom icon shown, but when I compare the displayed source code with mine,
I can see no difference. The file is on the hdd and set to "read only" (and works on the tablet)...

Another thing I don't get working is to display a picture full screen on the android wear...
Do you by chance have testetd that yourself and could help me out with a little bit of code? That would be awesome...

And one last question:
If I have an action, what would I need to do to run a sub on my main activity?

Thanks again a lot and best regards,

Chris
 

barx

Well-Known Member
Licensed User
Longtime User
I'm struggling to follow what isn't working. Can you explain in full what isn't working and what you are trying to achieve.

A picture showing a similar example may help.
 

CryoGenID

Active Member
Licensed User
Longtime User
I am sorry if you couldn't follow my problem description, English is not my primary language ;-)
I will now try it again, hopefully better ;-)

A problem which I had from the beginning (and am still having) is, that the "smallIcon" on the wearable device is not displayed if I use something other than "icon" (which then takes the application icon).

Here is a sub in which I try to send another icon (also attached to this post) for the "smallIcon" and for the action.
B4X:
Sub Button_Picture_Click
    Dim nb As NotificationBuilder
    Dim wearableExtender As NotificationWearableExtender
    nb.Initialize
    wearableExtender.Initialize

    nb.SmallIcon = "arrow1_b"
    nb.ContentTitle = "Some Title 2"
    nb.ContentText = "Some Text 2"
    wearableExtender.AddAction("arrow1" , "Wear1", "WearActionTag1", Notepopup)
    nb.Extend(wearableExtender)
    nb.Notify(1)

End Sub

What happens with the sub above:
1) When I run it exactly as it is quoted above, simply nothing happens on the watch. No notification whatsoever. As soon as I change the smallIcon back to "icon", the notification is displayed correctly.
2) When I leave the smallicon at "icon" (so that I get the notification at all) and then swipe over to the action, I see no icon in the blue round action button. So the "arrow1" is not displayed.

I am using a Nexus 7 (with Android 5.0.2) to run the app and the wear device is a Moto 360.

Here are the PNGs:
arrow1.png:

arrow1_b.png


Any chance you can help me to get this working:
1) Send another graphic for the smallIcon
2) Send a graphic for the action icon


Thanks a lot in advance and best regards,

Christian
 

barx

Well-Known Member
Licensed User
Longtime User


Unfortunately this is just the way Android Wear works. It uses the App Icon on the Wear device instead of the SmallIcon. I don't know of any way to change it. An only alternative I can think of is to hide the app Icon and the Add a ContentIcon. Like Below:

B4X:
    nb.Initialize
    wearableExtender.Initialize
    nb.DefaultSound = False
    nb.SmallIcon = "arrow1"
    nb.ContentTitle = "Some Title 2"
    nb.ContentText = "Some Text 2"
    wearableExtender.HideIcon = True
    wearableExtender.ContentIcon = "arrow1"
    wearableExtender.ContentIconGravity = wearableExtender.TOP
    wearableExtender.AddAction("arrow1" , "Wear1", "WearActionTag1", Notepopup)
    nb.Extend(wearableExtender)
    nb.Notify(1)

That will give you this:

 

Gentry

Member
Licensed User
Longtime User
I learned that if the SmallIcon value is not valid, that the notification will buzz, but the notification card does not get displayed.

the icon (88x88 96dpi) is in the files directory, is read only, and the project shows it on the files listing. however my reference in .SmallIcon = "img" (filename img.jpg) fails to display the notification.

when I changed .SmallIcon = "icon" it began to work as expected.

Thanks for the library!

Gentry
 

barx

Well-Known Member
Licensed User
Longtime User
You don't put the image in files. Read the docs again to find the right place...
 

Gentry

Member
Licensed User
Longtime User
Of course. \Objects\res\drawable\ has a read only icon.jpg file in it. No wonder it works
 

wes58

Active Member
Licensed User
Longtime User
I have compiled an application with targetSdkVersion 21 and noticed that the notification icon is very small.
When the same application (with the same icon) is compiled with targetSdkVersion less than 21, notification icon looks OK.
Any idea what the problem is? I have attached a photo showing both situations. I am using Galaxy S5 with Lollipop.

Edit:
If I use nb.LargeIcon in the notification than, in Lollipop it is displayed OK, but next to it (on the attached second photo) nb.SmallIcon is not readable.
Edit: Another test.
When compiled with targetSdkVersion less than 21, both large and small icons are displayed fine.
 

Attachments

  • Screenshot_2.png
    70.5 KB · Views: 261
  • Screenshot_3.png
    39.9 KB · Views: 272
Last edited:

mr23

Active Member
Licensed User
Longtime User
I found a 3 year old thread asking if 4+ click areas can be supported. That is similar to my need.
Is it possible to have a layout with more than 3 'actions' ?

I did create a version with 2 notifications, but would prefer the second one have actions only and no 'text row'.
Is it possible to use addAction's (addAction2) but with no text, on the 'text row' ? My attempts have not been fruitful yet.
 

barx

Well-Known Member
Licensed User
Longtime User

You cannot have more than 3 actions (android restriction). You could create a custom layout with 4+ imageviews (or similar) and add a clicklistener to them for them to act like actions.

This is not for the faint hearted. Custom layout have to be made in XML files.
 

mr23

Active Member
Licensed User
Longtime User
In the layout file, the ImageView have id form "@+id/abcd_imageviewname".
I've used setEnableClickEvent on a couple variants of that but it doesn't seem to be performing the event for the image view click.
What form/portion of this id should be used?

Update: Nevermind. Everything after the id/. The one combo I didn't try.
Thanks for this example, barx.
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
> This is not for the faint hearted. Custom layout have to be made in XML files.


barx: By the way, I was able to use my widget remoteviews layout directly from the designer.

Please, explain a little more..... I'm intrigued
 

mr23

Active Member
Licensed User
Longtime User
Please, explain a little more..... I'm intrigued

I had added a remoteviews based widget to my app. It is mostly ImageViews and Labels on Panels. The layout for it was created in the Designer. I was able to successfully reference the layout xml for it (that is stored in ...\Objects\res\layout) in the NotificationCustomLayout Initialize, and the view elements in setEnableClickEvent, and all of the click events work exactly as they do with the widget.

No fainting required. ;-)

One of several widget layouts used...

[I could have named the view elements better to reflect function...]
[URL if picture doesn't display]​

In the app I am able to select from the layouts, update the notification to the desired selection, and the notification display changes accordingly.
So effectively I now have my choice of widget layout in the notification area. It took just a notification class (that builds/updates the notification using your library, NotificationCustomLayout, BigCustomLayout, and setEnableClickEvent) and a notification service (that just maps the clicks/tags to the same class methods that the widget click events map to).

Update: I've updated the Share Your Creations thread for this app

By the time you're reading this v24 should be up on Play.
 
Last edited:

Bitcrawler

Member
Licensed User
Longtime User
Hi barx,

thank you for the great library!

I use it for a alarm clock with notification on a wearable. A simple notification works, no problem. But I want to add an action on the wearable that stops the sound when the alarm triggers. I understand, that I must use wearableExtender.AddAction for this. I read the tutorial more then one time, but I dont understand how it works
There is no complete sample code for this. In your demo apk you use
wearableExtender.AddAction("arrow1" , "Wear1", "WearActionTag1", Notepopup). Can you share the source code for the "Notepopup" activity? I think, this helps.

Thank you!
 

barx

Well-Known Member
Licensed User
Longtime User
in the service, all you need to do is check for the relevant Extra Tag in the starting intent like follows:

B4X:
Sub Activity_Resume
   Dim In As Intent
   Dim intentExtra As String

   In = Activity.GetStartingIntent
   Log(In.ExtrasToString)

   If In.HasExtra("Notification_Action_Tag") Then 'from a standard notification action
     intentExtra = In.GetExtra("Notification_Action_Tag")
     ToastMessageShow(intentExtra, False)
   End If
   
   If In.HasExtra("Notification_Wear_Action_Tag") Then 'from a Wear notification action
     If In.GetExtra("Notification_Wear_Action_Tag") = "RemAction" Then
       Dim rem As NotificationRemoteInput
       ToastMessageShow(rem.GetRemoteInput(In, "Action_Reply"), False)
     Else
       intentExtra = In.GetExtra("Notification_Wear_Action_Tag")
       ToastMessageShow(intentExtra, False)
     End If
   End If

End Sub
 

Albi

Active Member
Licensed User
Longtime User
hello,

This is a great library!
There are a couple of things which I need your help with.

I can't get the custom sounds to work.

in activity_create i do this:
B4X:
If FirstTime Then
        File.Copy(File.DirAssets,"alarmsound.mp3",File.DirDefaultExternal,"alarmsound.mp3")
End If

Then I run
B4X:
nb.CustomSound = "file:///" & File.Combine(File.DirDefaultExternal, "alarmsound.mp3")
to try to play the sound.

I've tried DirInternal as well as DirDefaultExternal but in both cases it just plays the default sound.

I was also wondering if there was a way to loop the custom sounds, or keep the sound playing until the user stops it?

Thanks!
 

barx

Well-Known Member
Licensed User
Longtime User


Can you post an example project with the non working code and the sound file. Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…