Created
February 15, 2014 18:10
-
-
Save dvas0004/9022987 to your computer and use it in GitHub Desktop.
http://blog.davidvassallo.me/2014/02/09/sl4a-python-4-android-bluetooth-and-webviews-example/ : bluetooth server example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android | |
import time | |
droid = android.Android() | |
droid.toggleBluetoothState(True) | |
droid.dialogCreateAlert('Be a server?') | |
droid.dialogSetPositiveButtonText('Yes') | |
droid.dialogSetNegativeButtonText('No') | |
droid.dialogShow() | |
result = droid.dialogGetResponse() | |
is_server = result.result['which'] == 'positive' | |
if is_server: | |
droid.bluetoothMakeDiscoverable() | |
droid.bluetoothAccept() | |
else: | |
droid.bluetoothConnect() | |
if is_server: | |
result = droid.dialogGetInput('Chat', 'Enter a message').result | |
if result is None: | |
droid.exit() | |
droid.bluetoothWrite(result + '\n') | |
while True: | |
result = droid.dialogGetInput('Chat', 'Enter a message').result | |
if result is None: | |
break | |
droid.bluetoothWrite(result + '\n') | |
droid.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment