B4A Library Notification Builder Library.

Albi

Active Member
Licensed User
Longtime User
Example attached.
Thanks!
 

Attachments

  • Alarm.zip
    265.8 KB · Views: 324

barx

Well-Known Member
Licensed User
Longtime User
Example attached.
Thanks!
OK, I changed

B4X:
File.DirInternal
to
B4X:
File.DirDefaultExternal
and it works fine. No idea why but it doesn't seem to read from DirInternal, don't know if it is a permissions issue or what. Someone else may be able to help with that.

Another option if you are packaging the sound with your app would be to put the file in


Set it to read only (so the compiler doesn't delete it) and then use

B4X:
nb.CustomSound = "android.resource://" + yourPackageName + "/" R.raw.alarmsound
 

barx

Well-Known Member
Licensed User
Longtime User
As for playing the sound constantly, I don't believe it is possible with any notification setting.

I would probably use MediaPlayer to play the file from the service. And therefore disable the notification sound alltogether.
 

Albi

Active Member
Licensed User
Longtime User
sorry, i changed the code to
B4X:
File.DirDefaultExternal
but that still didn't work for me. I tried changing it in just the main module and just the service module, and in both but it didn't work.
I also do not quite understand the other option of using the res folder. should 'yourpackagename' be a string rather than a variable? should the + be &? and what is 'R'?
so something like
B4X:
nb.CustomSound = "android.resource://yourPackageName/" & R.raw.alarmsound
I just don't know what 'R' is supposed to be?

Sorry for all the trouble. I may try to use the mediaplayer in the services module instead.

edit: it also didn't let me compile with the mp3 file in the res folder. however, using the mediaplayer worked fine, thanks for your help!
 

barx

Well-Known Member
Licensed User
Longtime User
try the attached file
 

Attachments

  • alarm2.zip
    265.3 KB · Views: 327

Albi

Active Member
Licensed User
Longtime User
Thanks, I just tried that and it just plays the default sound! I'm now guessing that my phone is perhaps a little odd (it's an HTC One X+).
 

barx

Well-Known Member
Licensed User
Longtime User
Thanks, I just tried that and it just plays the default sound! I'm now guessing that my phone is perhaps a little odd (it's an HTC One X+).
What was shown in the log as you ran it (I added a couple of log()s )
 

Albi

Active Member
Licensed User
Longtime User
aha yes! here they are.

Installing file.
PackageAdded: package:b4a.alarm
~i:Copying updated assets files (2)
~i:** Activity (main) Create, isFirst = true **
copying sound
true
** Activity (main) Resume **
~i:** Activity (main) Pause, UserClosed = true **
~i:** Service (alarmservices) Create **
** Service (alarmservices) Start **
file:///data/data/b4a.alarm/files/alarmsound.mp3

edit: and this is the line for log of dirDefaultExternal
file:///storage/emulated/0/Android/data/b4a.alarm/files/alarmsound.mp3
 

barx

Well-Known Member
Licensed User
Longtime User
This project uses the Media Player I was talking about to loop the sound.
 

Attachments

  • alarm2.zip
    265.4 KB · Views: 293

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
someone please can help me with this log error?

B4X:
** Service (pushservice) Create **

Sub Process_Globals
Dim NotPart As NotificationBuilder
end sub

Sub MessageArrived (Intent As Intent)

NotPart.Initialize
NotPart.SmallIcon = "icon"
NotPart.Ticker = "Fortitudo Vedelago"
NotPart.Tag = "some tag"
NotPart.setActivity(Me)
NotPart.setCustomLight(Colors.ARGB(255,198,78,24), 50, 50)
NotPart.DefaultLight = True
NotPart.DefaultVibrate = False
NotPart.DefaultSound = False
NotPart.CustomSound = File.DirRootExternal & "/Fortitudo Vedelago/notifica.mp3"
NotPart.ContentTitle = "Risultato Partita"
NotPart.ContentText = "Campionato: " & Data.SubString2(0, Data.IndexOf("-*-"))
NotPart.SubText = Data.SubString2(Data.IndexOf("-*-") + 3, Data.Length)
Dim MyApp As Intent : Dim pm As PackageManager : MyApp = pm.GetApplicationIntent("simone.b.fortitudovedelago")
NotPart.setIntent(MyApp)
NotPart.Notify(1)
End Sub

** Service (pushservice) Start **


java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/NotificationManagerCompat;


    at barxdroid.NotificationBuilder.NotificationBuilder.Notify(NotificationBuilder.java:512)
    at simone.b.fortitudovedelago.pushservice._messagearrived(pushservice.java:287)
    at simone.b.fortitudovedelago.pushservice._service_start(pushservice.java:424)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at simone.b.fortitudovedelago.pushservice.handleStart(pushservice.java:68)
    at simone.b.fortitudovedelago.pushservice.onStartCommand(pushservice.java:53)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3261)
    at android.app.ActivityThread.access$2200(ActivityThread.java:172)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1520)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5834)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.app.NotificationManagerCompat" on path: DexPathList[[zip file "/mnt/asec/simone.b.fortitudovedelago-6/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 19 more
    Suppressed: java.lang.ClassNotFoundException: android.support.v4.app.NotificationManagerCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 20 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

When the event notify start, the app crash
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Up.. Please
 
Last edited:

Kevin

Well-Known Member
Licensed User
Longtime User
It seems that most issues like yours have been caused by either an old version of "android-support-v4.jar" in the B4A extra libs folder or a copy of it in both the extra libs and normal B4A libs folder.

Try updating your Android SDK then copy the latest version of that file into your extra libs folder and make sure there is no copy of it in the normal libs folder.
 

bitben

Member
Licensed User
Longtime User
Hello, don't know if i have to open a new thread or can post my problem here.

B4X:
Dim nb As NotificationBuilder
nb.Initialize
nb.SmallIcon = "icon"
nb.Ticker = "Quickscan ready"
nb.Tag = "Tag"
nb.setActivity(Me)
nb.DefaultLight = False
nb.DefaultSound = False
nb.DefaultVibrate = False
nb.ContentTitle = "Ready for scan"
nb.SubText = "Press to scan"
nb.ShowTime = False
nb.AddAction("Barcode_scanner", "Scan ready", "Button1", Me )

This is my code, it works fine. But when i call
B4X:
nb.Notifiy(1)
there comes an error:
java.lang.NoClassDefFoundError: android.support.v4.app.NotificationManagerCompat

Java jdk1.8.0
android-22
Android SDK Manager is up to date with Android 5.1.1 (API 22)

What is wrong?
 

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
I have this code:
B4X:
Dim cn As NotificationBuilder
Dim cn1 As NotificationBigTextStyle
   
    If  cn.IsInitialized = False Then  cn.Initialize
    cn.SmallIcon = "icon"


    cn.DefaultLight = True
    cn.DefaultVibrate = True
    cn.DefaultSound = True
    cn.setActivity(mainonline)
    cn.ContentInfo = "Devil-App"
    cn.AutoCancel = True
   
    If cn1.IsInitialized = False Then cn1.Initialize
   
    cn1.BigText = Data
    cn1.SummaryText = "Read More..."
   
    cn.ContentTitle = "TATTOO"
   
    cn.SetStyle(cn1)
    cn.Notify(Num_notify)
    Num_notify=Num_notify+1


i have this effect... when the notification arrives for a moment i see the message.... as figura 1





and then closes... as figura 2



Exist one way for avoid this ??
Thank you
Marco
 

barx

Well-Known Member
Licensed User
Longtime User
I don't really understand what issue you have. it looks ok to me, that is how it is supposed to work and you pinch in and out to close and expand
 

MarcoRome

Expert
Licensed User
Longtime User
I don't really understand what issue you have. it looks ok to me, that is how it is supposed to work and you pinch in and out to close and expand
Thanks for your response... the question is possible expand for all time without close
 

barx

Well-Known Member
Licensed User
Longtime User
Thanks for your response... the question is possible expand for all time without close
Ah I see, for that I think you would have to create a custom layout....
 

G-ShadoW

Active Member
Licensed User
Longtime User
is it possible to use intent from notification ?

B4X:
Dim market As Intent, uri As String
            uri="http://www.some.com/"
            market.Initialize(market.ACTION_VIEW,uri)
            StartActivity(market)

nb.AddAction2("info","<<< CLICK HERE >>>","Open",StartActivity(market))

>Solved, I didnt see .SetIntent option
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…