programandoconro
programandoconro

Reputation: 2729

Monaca Android App crashes when cordova-plugin-local-notification tries to play a mp3 file

I am new with monaca/cordova and I am trying to get a background notification with sound using React framework and this plugin: https://github.com/katzer/cordova-plugin-local-notifications. I am building the App in an Android 10 device. When I try the notification without sound, it works fine, but when adding a sound, it CRASHES. This is the log for the error:

    at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:584)
    at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558)
    at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
    at de.appplant.cordova.plugin.notification.util.AssetUtil.getUriFromFile(AssetUtil.java:357)
    at de.appplant.cordova.plugin.notification.util.AssetUtil.getUriFromAsset(AssetUtil.java:147)
    at de.appplant.cordova.plugin.notification.util.AssetUtil.parse(AssetUtil.java:90)
    at de.appplant.cordova.plugin.notification.Options.getSound(Options.java:351)
    at de.appplant.cordova.plugin.notification.Builder.build(Builder.java:126)
    at de.appplant.cordova.plugin.localnotification.TriggerReceiver.buildNotification(TriggerReceiver.java:130)
    at de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver.onReceive(AbstractTriggerReceiver.java:60)
    at de.appplant.cordova.plugin.notification.Notification.trigger(Notification.java:265)
    at de.appplant.cordova.plugin.notification.Notification.schedule(Notification.java:217)
    at de.appplant.cordova.plugin.notification.Manager.schedule(Manager.java:102)
    at de.appplant.cordova.plugin.localnotification.LocalNotification.schedule(LocalNotification.java:271)
    at de.appplant.cordova.plugin.localnotification.LocalNotification.access$400(LocalNotification.java:62)
    at de.appplant.cordova.plugin.localnotification.LocalNotification$1.run(LocalNotification.java:146)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)

This is the function I am using to get the notification (works fine if the sound is not added).

 const showNotification = () => {
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
      console.log(cordova.plugins.notification.local.schedule);
    }
   cordova.plugins.notification.local.schedule({
      id: 1,
      title: "Alarm Time",
      text: String(value),
      trigger: { at: value },
      sound: "file://assets/songs/samplesong.mp3" // <-- this is where the error occurs. 
    });
  };

*(value is a Date() selected by the user).

This is my config.xml file:

<widget xmlns="http://www.w3.org/ns/widgets" id="com.example.helloworld" version="1.0.0">
  <name>Onsen UI v2 React Minimum</name>
  <description>Made with Monaca (http://monaca.mobi)</description>
  <author/>
  <access origin="*"/>
  <content src="index.html"/>
  <preference name="loglevel" value="DEBUG"/>
  <preference name="AndroidLaunchMode" value="singleTop"/>
  <preference name="BackgroundColor" value="0xffffffff"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="ErrorUrl" value=""/>
  <preference name="Fullscreen" value="false"/>
  <preference name="KeepRunning" value="true"/>
  <preference name="monaca:WebViewEngine" value="default"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="1000"/>
  <preference name="Orientation" value="default"/>
  <preference name="monaca:DisableCookie" value="false"/>
  <preference name="monaca:AndroidIsPackageNameSeparate" value="false"/>
  <preference name="AllowInlineMediaPlayback" value="false"/>
  <preference name="AutoHideSplashScreen" value="true"/>
  <preference name="BackupWebStorage" value="cloud"/>
  <preference name="EnableViewportScale" value="false"/>
  <preference name="FadeSplashScreen" value="true"/>
  <preference name="FadeSplashScreenDuration" value="250"/>
  <preference name="KeyboardDisplayRequiresUserAction" value="true"/>
  <preference name="MediaPlaybackRequiresUserAction" value="false"/>
  <preference name="ShowSplashScreenSpinner" value="false"/>
  <preference name="SuppressesIncrementalRendering" value="false"/>
  <preference name="TopActivityIndicator" value="gray"/>
  <preference name="GapBetweenPages" value="0"/>
  <preference name="PageLength" value="0"/>
  <preference name="PaginationBreakingMode" value="page"/>
  <preference name="PaginationMode" value="unpaginated"/>
  <preference name="ios-XCBuildConfiguration-TARGETED_DEVICE_FAMILY" value="1,2"/>
  <feature name="App">
    <param name="android-package" value="org.apache.cordova.App"/>
  </feature>
  <feature name="LocalStorage">
    <param name="ios-package" value="CDVLocalStorage"/>
  </feature>
  <platform name="ios">
    <preference name="orientation" value="all"/>
    <splash src="/res/ios/screen/Default@2x~universal~anyany.png"/>
    <icon src="/res/ios/icon/icon.png" width="57" height="57"/>
    <icon src="/res/ios/icon/[email protected]" width="114" height="114"/>
    <icon src="/res/ios/icon/icon-72.png" width="72" height="72"/>
    <icon src="/res/ios/icon/[email protected]" width="144" height="144"/>
    <icon src="/res/ios/icon/icon-60.png" width="60" height="60"/>
    <icon src="/res/ios/icon/[email protected]" width="120" height="120"/>
    <icon src="/res/ios/icon/[email protected]" width="180" height="180"/>
    <icon src="/res/ios/icon/icon-76.png" width="76" height="76"/>
    <icon src="/res/ios/icon/[email protected]" width="152" height="152"/>
    <icon src="/res/ios/icon/icon-40.png" width="40" height="40"/>
    <icon src="/res/ios/icon/[email protected]" width="80" height="80"/>
    <icon src="/res/ios/icon/icon-50.png" width="50" height="50"/>
    <icon src="/res/ios/icon/[email protected]" width="100" height="100"/>
    <icon src="/res/ios/icon/icon-small.png" width="29" height="29"/>
    <icon src="/res/ios/icon/[email protected]" width="58" height="58"/>
    <icon src="/res/ios/icon/[email protected]" width="87" height="87"/>
    <icon src="/res/ios/icon/icon-83.5@2x~ipad.png" width="167" height="167"/>
    <icon src="/res/ios/icon/icon-1024.png" width="1024" height="1024"/>
    <splash src="/res/ios/screen/Default@2x~universal~anyany.png"/>
    <config-file platform="ios" parent="CFBundleLocalizations" target="*-Info.plist">
      <array>
        <string>en</string>
      </array>
    </config-file>
  </platform>
  <platform name="android">
    <icon src="/res/android/icon/ldpi.png" density="ldpi"/>
    <icon src="/res/android/icon/mdpi.png" density="mdpi"/>
    <icon src="/res/android/icon/hdpi.png" density="hdpi"/>
    <icon src="/res/android/icon/xhdpi.png" density="xhdpi"/>
    <icon src="/res/android/icon/xxhdpi.png" density="xxhdpi"/>
    <icon src="/res/android/icon/xxxhdpi.png" density="xxxhdpi"/>
    <splash src="/res/android/screen/splash-port-ldpi.9.png" density="port-ldpi"/>
    <splash src="/res/android/screen/splash-port-mdpi.9.png" density="port-mdpi"/>
    <splash src="/res/android/screen/splash-port-hdpi.9.png" density="port-hdpi"/>
    <splash src="/res/android/screen/splash-port-xhdpi.9.png" density="port-xhdpi"/>
    <splash src="/res/android/screen/splash-port-xxhdpi.9.png" density="port-xxhdpi"/>
    <splash src="/res/android/screen/splash-port-xxxhdpi.9.png" density="port-xxxhdpi"/>
    <splash src="/res/android/screen/splash-mdpi.png" density="mdpi"/>
  </platform>
  <platform name="electron">
    <icon src="/res/electron/icon/icon_electron_512.png" width="512" height="512"/>
    <splash src="/res/electron/screen/electron_splash_image.png" width="620" height="300"/>
    <preference name="SplashScreenWidth" value="620"/>
    <preference name="SplashScreenHeight" value="300"/>
    <preference name="ShowSplashScreen" value="false"/>
  </platform>
  <preference name="WindowsStorePublisherName" value="My Name"/>
  <preference name="WindowsStoreIdentityName" value="b88890db-d285-d39c-671d-89a187a00094"/>
</widget>

Upvotes: 0

Views: 325

Answers (1)

Primata L&#243;gico
Primata L&#243;gico

Reputation: 745

Try writing the path with one "/":

sound: "file:/assets/songs/samplesong.mp3"

Upvotes: 0

Related Questions