Android Question NB6 custom sounds

Discussion in 'Android Questions' started by Tomas Petrus, Jan 15, 2019.

  1. Tomas Petrus

    Tomas Petrus Active Member Licensed User

    I managed to implement almost all the functionality I needed, but I am stuck with custom sounds.

    What am I missing ?

    Code:
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28"/>
    Testing on Android 9.0.11

    Code:
    Sub Notification (nid As Int, Channel As String, Title As String, Body As String, Priority As String, Tag As String, Sound As String)
        
    'pro moje zvuky
        Dim rp As RuntimePermissions
        
    Dim folder As String = rp.GetSafeDirDefaultExternal("shared")
        
    Dim FileName As String = "novaAukce.mp3"
        
    'copy the file to the shared folder
        File.Copy(File.DirAssets, FileName, folder, FileName)
        
    'pro moje zvuky
     
        
    Dim n As NB6
        n.Initialize(Channel, 
    Application.LabelName, Priority).AutoCancel(True)
        n.SmallIcon(LoadBitmapResize(
    File.DirAssets, "smiley.png"32dip32dipTrue))
        
    'disable the default sound
        n.SetDefaults(FalseTrueTrue)
        
    'set custom sound
        n.CustomSound(CreateFileProviderUri(folder, FileName))
    End Sub

    'pro moje zvuky
    Sub CreateFileProviderUri (Dir As String, FileName As StringAs Object
        
    Dim FileProvider As JavaObject
        
    Dim context As JavaObject
        context.InitializeContext
        FileProvider.InitializeStatic(
    "android.support.v4.content.FileProvider")
        
    Dim f As JavaObject
        f.InitializeNewInstance(
    "java.io.File"Array(Dir, FileName))
        
    Return FileProvider.RunMethod("getUriForFile"Array(context, Application.PackageName & ".provider", f))
    End Sub
    Code:
    Error occurred on line: 75 (Repo)
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4j.object.JavaObject.RunMethod(
    JavaObject.java:131)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:732)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:348)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:255)
        at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:
    265)
        at cz.esol.edispecink.repo._
    notification(repo.java:178)
        at cz.esol.edispecink.repo._novaprirazena(repo.java:
    87)
        at cz.esol.edispecink.tracker._timerstatus_tick(tracker.java:
    720)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:732)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:351)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:255)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    144)
        at anywheresoftware.b4a.objects.Timer$TickTack.run(
    Timer.java:105)
        at android.os.Handler.handleCallback(Handler.java:
    873)
        at android.os.Handler.dispatchMessage(Handler.java:
    99)
        at android.os.Looper.loop(Looper.java:
    193)
        at android.app.ActivityThread.main(ActivityThread.java:
    6863)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:
    537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    858)
    Caused by: java.lang.NullPointerException: Attempt 
    to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
        at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605)
        at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:
    579)
        at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:
    417)
        ... 
    24 more
     
    Last edited: Jan 15, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is a mistake to set targetSdkVersion to 28. Set it to 26 for now.

    Try the NB6 example. Does the custom sound work?

    You probably missed the file provider manifest editor code. Note that it is better to use the newer FileProvider class.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice