mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
enhance receiver to get BT on/off and connect attempts and to start
bt service in response.
This commit is contained in:
parent
6982545f59
commit
cc9f2b793e
2 changed files with 36 additions and 0 deletions
|
@ -23,6 +23,8 @@ package org.eehouse.android.xw4;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
|
||||||
public class BTReceiver extends BroadcastReceiver {
|
public class BTReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@ -30,5 +32,24 @@ public class BTReceiver extends BroadcastReceiver {
|
||||||
public void onReceive( Context context, Intent intent )
|
public void onReceive( Context context, Intent intent )
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "BTReceiver.onReceive()" );
|
DbgUtils.logf( "BTReceiver.onReceive()" );
|
||||||
|
String action = intent.getAction();
|
||||||
|
DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action );
|
||||||
|
if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) {
|
||||||
|
BTService.startService( context );
|
||||||
|
} else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) {
|
||||||
|
int newState =
|
||||||
|
intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 );
|
||||||
|
switch ( newState ) {
|
||||||
|
case BluetoothAdapter.STATE_OFF:
|
||||||
|
BTService.radioChanged( context, false );
|
||||||
|
break;
|
||||||
|
case BluetoothAdapter.STATE_ON:
|
||||||
|
BTService.radioChanged( context, true );
|
||||||
|
break;
|
||||||
|
case BluetoothAdapter.STATE_TURNING_ON:
|
||||||
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,13 @@ public class BTService extends Service {
|
||||||
private static final int SCAN = 1;
|
private static final int SCAN = 1;
|
||||||
private static final int INVITE = 2;
|
private static final int INVITE = 2;
|
||||||
private static final int SEND = 3;
|
private static final int SEND = 3;
|
||||||
|
private static final int RADIO = 4;
|
||||||
|
|
||||||
private static final String CMD_STR = "CMD";
|
private static final String CMD_STR = "CMD";
|
||||||
private static final String MSG_STR = "MSG";
|
private static final String MSG_STR = "MSG";
|
||||||
private static final String TARGET_STR = "TRG";
|
private static final String TARGET_STR = "TRG";
|
||||||
private static final String ADDR_STR = "ADR";
|
private static final String ADDR_STR = "ADR";
|
||||||
|
private static final String RADIO_STR = "RDO";
|
||||||
|
|
||||||
private static final String GAMEID_STR = "GMI";
|
private static final String GAMEID_STR = "GMI";
|
||||||
|
|
||||||
|
@ -140,6 +142,14 @@ public class BTService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void radioChanged( Context context, boolean cameOn )
|
||||||
|
{
|
||||||
|
Intent intent = new Intent( context, BTService.class );
|
||||||
|
intent.putExtra( CMD_STR, RADIO );
|
||||||
|
intent.putExtra( RADIO_STR, cameOn );
|
||||||
|
context.startService( intent );
|
||||||
|
}
|
||||||
|
|
||||||
public static void rescan( Context context ){
|
public static void rescan( Context context ){
|
||||||
Intent intent = new Intent( context, BTService.class );
|
Intent intent = new Intent( context, BTService.class );
|
||||||
intent.putExtra( CMD_STR, SCAN );
|
intent.putExtra( CMD_STR, SCAN );
|
||||||
|
@ -237,6 +247,11 @@ public class BTService extends Service {
|
||||||
addr, gameID ) );
|
addr, gameID ) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case RADIO:
|
||||||
|
boolean cameOn = intent.getBooleanExtra( RADIO_STR, false );
|
||||||
|
BTEvent evt = cameOn? BTEvent.BT_ENABLED : BTEvent.BT_DISABLED;
|
||||||
|
sendResult( evt );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue