Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-5239

Android: if you add a sound to a notification the sound is not found

    Details

      Description

      Problem

      If you add a sound to a notification the sound is not found.

      http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.NotificationManager-module

      Repro sequence

      app.js

      var win= Titanium.UI.createWindow();
       
      var btn = Ti.UI.createButton({
        title: 'Add Notification'
      });
       
      btn.addEventListener('click', function(e) {
       
        var activity = Ti.Android.currentActivity();
        var intent = Ti.Android.createIntent({
        });
       
        var pending = Ti.Android.createPendingIntent({ 
          'activity' : activity,
          'intent' : intent,
          'type' : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
          'flags' : 1073741824
        });
       
        var ts = new Date().getTime();
       
        var notification = Ti.Android.createNotification({
          contentIntent : pending,
          contentTitle : 'Test',
          contentText : 'test',
          when : ts,
          //icon: 'KS_nav_ui.png',TIMOB-4651
          sound: '1.mp3',
          defaults: Titanium.Android.NotificationManager.DEFAULT_VIBRATE
        });
       
        Ti.Android.NotificationManager.notify(1, notification);  
      });
      win.add(btn);
       
      // testing if the image exist
      var lbl = Titanium.UI.createLabel({
        text : '     ',
        backgroundImage: 'KS_nav_ui.png',
        top : 10,
        left: 10
      });
       
      win.add(lbl);
       
      win.open();
      

      Console Output - With customized Sound

      Sound file is located at resources folder, so property is being set as:
      sound: '1.mp3'

       I/StagefrightPlayer(   34): setDataSource('/android_asset/Resources/1.mp3')
      E/MediaPlayer(   60): error (1, -2147483648)
      W/NotificationService(   60): error loading sound for file:///android_asset/Resources/1.mp3
      W/NotificationService(   60): java.io.IOException: Prepare failed.: status=0x1
      W/NotificationService(   60): 	at android.media.MediaPlayer.prepare(Native Method)
      W/NotificationService(   60): 	at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:90)
      

      Tested on

      Device: HTC Dream Android 2.2 OS version & Emulator: Android HGVA

      Associated HD ticket

      PRO - http://appc.me/c/APP-923324

      Additional info

      Get default vibrate by setting permissions in Tiapp.xml

          <android xmlns:android="http://schemas.android.com/apk/res/android">  
          	<manifest>  	
          		<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
          	</manifest>	
          </android>
      

      Work Around

      To allow the app at this time to play the default sound and vibration as well:
      defaults: Titanium.Android.NotificationManager.DEFAULT_ALL

      To play default sound:
      defaults: Titanium.Android.NotificationManager.DEFAULT_SOUND

      To get phone vibration:
      defaults: Titanium.Android.NotificationManager.DEFAULT_VIBRATE

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hpham Hieu Pham
                Reporter:
                egomez Eduardo Gomez (Inactive)
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-4435
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code