Android Question NB6: Unable to make CustomVibrate working

toby

Well-Known Member
Licensed User
Longtime User
I'm using this nb6 example . I want to add a custom vibration to "Notification with Custom Sound".

B4X:
Sub Notification_WithCustomSound
    Dim rp As RuntimePermissions
    Dim folder As String = rp.GetSafeDirDefaultExternal("shared")
    Dim FileName As String = "shotgun.mp3"
    'copy the file to the shared folder
    File.Copy(File.DirAssets, FileName, folder, FileName)
    Dim n As NB6
    n.Initialize("custom sound", Application.LabelName, "DEFAULT")
    n.SmallIcon(LoadBitmapResize(File.DirAssets, "smiley.png", 32dip, 32dip, True))
    'disable the default sound
    [COLOR=rgb(226, 80, 65)]n.SetDefaults(False, True, False)[/COLOR] 'last parameter changed from True to False
    'set custom sound
    n.CustomSound(CreateFileProviderUri(folder, FileName))
    
    [COLOR=rgb(235, 107, 86)]n.CustomVibrate(Array As Long(0, 1000, 1000, 1000)) 'line added'[/COLOR]
    
    Dim Notification As Notification = n.Build("Notification with custom sound", "...", "", Me)
    Notification.Notify(3)
    
    
End Sub

I only got the custom sound without vibration. Could someone kindly tell me what went wrong?


Logger connected to: samsung SM-T560NU
--------- beginning of main
SS_ART_lib : permission is absent: /data/app/b4x.example-1/base.apk
SS_ART_lib : access to SS denied
SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=b4x.example
ClassLoader referenced unknown path: /data/app/b4x.example-1/lib/arm
Class androidx.core.content.FileProvider failed lock verification and will run slower.
Common causes for lock verification issues are non-optimized dex code
and incorrect proguard optimizations.
Class androidx.core.content.ContextCompat failed lock verification and will run slower.
Class anywheresoftware.b4a.BA failed lock verification and will run slower.
common created.
Starting remote logger. Port: 32633
ThreadedRenderer.create() translucent=false
Input channel constructed: fd=59
setView = DecorView@c86f1ff[main] touchMode=true
dispatchAttachedToWindow
Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][800,1280] result=0x27 surface={isValid=true -1513101312} surfaceGenerationChanged=true
mHardwareRenderer.initialize() mSurface={isValid=true -1513101312} hwInitialized=true
<qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8916_32_LA.BR.1.2.9_RB1__release_AU (I750f7f2fa6)
OpenGL ES Shader Compiler Version: XE031.09.00.03
Build Date: 02/18/17 Sat
Local Branch:
Remote Branch: quic/LA.BR.1.2.9_rb1.12
Local Patches: NONE
Reconstruct Branch: NOTHING
Initialized EGL, version 1.4
Swap behavior 1
<qeglDrvAPI_eglCreateContext:2475>: EGL_BAD_ATTRIBUTE
KHR Debugger is Disabled - EGL_BAD_ATTRIBUTE
*** Debugger waiting for connection (0) ***
MSG_RESIZED_REPORT: frame=Rect(0, 0 - 800, 1280) ci=Rect(0, 24 - 0, 0) vi=Rect(0, 24 - 0, 0) or=1
MSG_WINDOW_FOCUS_CHANGED 1
mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true -1513101312}
Starting input: tba=android.view.inputmethod.EditorInfo@440f8b8 nm : b4x.example ic=null
startInputInner - mService.startInputOrWindowGainedFocus
Input channel constructed: fd=64
Input channel constructed: fd=65
setView = android.widget.LinearLayout{c90c9f6 V.E...... ......I. 0,0-0,0} touchMode=true
Text: Xait in android.widget.Toast$TN@17321f7
Starting input: tba=android.view.inputmethod.EditorInfo@e68e864 nm : b4x.example ic=null
dispatchAttachedToWindow
After accept
Relayout returned: oldFrame=[0,0][0,0] newFrame=[256,1172][543,1216] result=0x27 surface={isValid=true -1808089088} surfaceGenerationChanged=true
MSG_RESIZED_REPORT: frame=Rect(256, 1172 - 543, 1216) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
*** Debugger waiting for connection (1) ***
Copying updated assets files (4)
*** Service (starter) Create ***
** Service (starter) Start **
dispatchDetachedFromWindow
Input channel destroyed: fd=65
** Activity (main) Create, isFirst = true **
setTypeface with style : 0
initGoToTop
** Activity (main) Resume **
Relayout returned: oldFrame=[0,0][800,1280] newFrame=[0,0][800,1280] result=0x1 surface={isValid=true -1513101312} surfaceGenerationChanged=false
onsize change changed
ViewPostImeInputStage processPointer 0
ViewPostImeInputStage processPointer 1
Background sticky concurrent mark sweep GC freed 67698(2MB) AllocSpace objects, 4(80KB) LOS objects, 81% free, 2MB/14MB, paused 5.862ms total 70.882ms

 

toby

Well-Known Member
Licensed User
Longtime User
There is no CustomVibrate method in NB6.
I forgot to mention that I use the CustomVibrate function added by @wes58
CustomVibrate() by@wes58:
'Set the vibration pattern to use.
'Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds
'The first value indicates the number of milliseconds to wait before turning the vibrator on.
'The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off... And so on
Public Sub CustomVibrate(vibPatern() As Long) As NB6
 If IsChannel Then
  Channel.RunMethod("setVibrationPattern", Array(vibPatern))
 Else
  If Not(IsOld) Then
   nDefaults = Bit.And(nDefaults, 1 + 4) 'clear bit 1
  End If
  NotificationBuilder.RunMethod("setVibrate", Array(vibPatern))
 End If
 Return Me
End Sub
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
I forgot to mention that I use the CustomVibrate function added by @wes58
You noted this line in the thread you quoted:
If the provided pattern is valid (non-null, non-empty), will enable vibration as well. Otherwise, vibration will be disabled. Only modifiable before the channel is submitted.

And this:
8. I have noticed that Sub setDefaults(sound, light, vibration) in NB6 doesn't work correctly when used with Notifications with and without Channels
For API >= 26
setDefaults(false, false, false) means - no sound, no lights, no vibration
setDefaults(ture, true, true) means - enable sound (default, or custom if provided), enable light (default color or custom if provided),
enable vibration(default vibration pattern or custom if provided)
For API < 26
setDefaults(false, false, false) means - custom sound, custom lights and custom vibration pattern
setDefaults(true, true, true) means - default sound, default lights color and defualt vibration pattern.

So, true values mean "enable..." (default or custom for API >= 26, and default only for API < 26.
Therefore I had to modify existing sub CustomSound in NB6.
I also had to modify sub Build:
 
Last edited:
Upvote 0
Top