Notification sound - Please test

1,633 views
Skip to first unread message

Steve Garman

unread,
Jan 5, 2016, 7:18:32 PM1/5/16
to DroidScript
/*
Could people please test on various devices
and let me know whether it makes a
notification sound
*/

//Create media player. 
var player = app.CreateMediaPlayer(); 
     
//Called when application is started.
function OnStart()
{
    //Load a file (can be ogg or mp3). 
    var spec=app.GetSpecialFolder("notifications");
    var snd=app.ListFolder(spec,"ogg")[0];
    if(snd)
    {
        snd=spec+"/"+snd;
        player.SetFile( snd, "Snd" ); 
    }
    else app.Alert("No sound available");
    //Create a layout with objects vertically centered.
    var lay = app.CreateLayout( "linear", "VCenter,FillXY" );    

    //Create a button and add it to layout.
    var btn = app.CreateButton( "Notify" );
    btn.SetOnTouch(notify);
    btn.SetTextSize( 32 );
    lay.AddChild( btn );
    
    //Add layout to app.    
    app.AddLayout( lay );
}

function notify()
{
    var notify1=app.CreateNotification();
    notify1.SetMessage( "You have a notification!", "My Title", "My Details" ); 
    notify1.Notify("oneOnly");  
    player.SeekTo( 0 ); 
    player.Play(); 
}

Chris

unread,
Jan 6, 2016, 12:02:14 AM1/6/16
to DroidScript
Steve,

I got the no sound available alert.

Michael Seymour

unread,
Jan 6, 2016, 1:03:02 AM1/6/16
to DroidScript
Hi Steve, yup same as Chris. No sound available

Steve Garman

unread,
Jan 6, 2016, 1:33:26 AM1/6/16
to DroidScript
Ok thanks guys, the sound must be placed there by some app I have installed on all my devices then. It was a bit of a long shot that it would be general.

I was trying to find a generic way to play a sound when I send a notification, as DroidScript seems to have no way to do that using standard Android stuff.

Obviously I can bundle a sound in my app but either way, I would be bypassing the main preferences and I don't want to be the only app waking the user at 4.00 am.

I suppose it's time to try the Android SDK docs and Stack Overflow to find out what I should be doing if I was using Java.

After that, I guess the alternatives are a plugin or an opt-in only user-setting with time constraints and a warning that it ignores the user's other settings.


Reply all
Reply to author
Forward
0 new messages