Back

SetBluetoothEnabled

Hello World

Enables Bluetooth on the device.

app.SetBluetoothEnabled( enable )

See Also: IsBluetoothEnabled, IsBluetoothOn, CreateBluetoothSerial

Example - Enabling Bluetooth

function OnStart()
{
    app.ShowProgress( "Enabling Bluetooth" );
    if( !app.IsBluetoothEnabled() )
        app.SetBluetoothEnabled( true );


    while( !app.IsBluetoothOn() ) app.Wait( 0.3 );
    app.HideProgress();
}
    Copy     Copy All       Run      

Example - En/Disable Bluetooth

var itv = 0;

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    btnSave = app.CreateButton( "Enable", 0.5, 0.1 );
    btnSave.SetOnTouch( btn_OnTouch );
    lay.AddChild( btnSave );

    btnLoad = app.CreateButton( "Disable", 0.5, 0.1 );
    btnLoad.SetOnTouch( btn_OnTouch );
    lay.AddChild( btnLoad );

    app.AddLayout( lay );
}

function btn_OnTouch()
{
    if( itv ) return;
    var op = this.GetText();

    if( op == "Enable" )
    {
        app.ShowProgress( "Enabling Bluetooth" );

        if( !app.IsBluetoothEnabled() )
            app.SetBluetoothEnabled( true );

        itv = setInterval( checkBtOn, 200 );
    }
    else
    {
        app.ShowProgress( "Disabling Bluetooth" );

        if( app.IsBluetoothEnabled() )
            app.SetBluetoothEnabled( false );

        itv = setInterval( checkBtOff, 200 );
    }
}

function CheckBtOn()
{
    if( app.IsBluetoothOn() )
    {
        app.HideProgress();
        app.ShowPopup( "Bluetooth is on" );
        clearInterval( itv );
        itv = 0;
    }
}


function CheckBtOff()
{
    if( !app.IsBluetoothOn() )
    {
        app.HideProgress();
        app.ShowPopup( "Bluetooth is off" );
        clearInterval( itv );
        itv = 0;
    }
}
Copy All       Run      
boolean