Bluetooth chatting app
import androidhelper
import time
android = androidhelper.Android()
android.toggleBluetoothState(True)
android.dialogCreateAlert('Be a server?')
android.dialogSetPositiveButtonText('Yes')
android.dialogSetNegativeButtonText('No')
android.dialogShow()
result = android.dialogGetResponse()
is_server = result.result['which'] == 'positive'
if is_server:
android.bluetoothMakeDiscoverable()
android.bluetoothAccept()
else:
android.bluetoothConnect()
if is_server:
result = android.getInput('Chat', 'Enter a message').result
if result is None:
android.exit()
android.bluetoothWrite(result + '\n')
while True:
message = droid.bluetoothReadLine().result
android.dialogCreateAlert('Chat Received', message)
android.dialogSetPositiveButtonText('Ok')
android.dialogShow()
android.dialogGetResponse()
result = android.getInput('Chat', 'Enter a message').result
if result is None:
break
android.bluetoothWrite(result + '\n')
android.exit()
Comments
Post a Comment