German ..und schon wieder Bluetooth...

Stefan080159

Member
Licensed User
Longtime User
Hallo,
ich spiele zur Zeit mit dem Bluetooth-Tutorial von Erel rum. Ich versuche ein Auto-Connect nach
"unterbrochener Verbindung" herzustellen. Das funzt eigentlich auch schon ganz gut wenn da nicht
jedes mal die Message von Android beim sichtbar machen des eigenen Gerätes um die Ecke käme.
"Eine Anwendung auf dem Gerät fordert die Berechtigung an, das Gerät 300 Sekunden lang für andere Bluetooth-Geräte sichtbar zu machen. Zulassen? Ja / Nein"
gibt es eine Möglichkeit, diese Msg-Box auszublenden bzw. ein True zu implentieren?

Frohe Weihnachten
Stefan
 

Stefan080159

Member
Licensed User
Longtime User

….kommt schon Jungs, muss doch möglich sein, dies msg-Box programmgesteuert zu umgehen....
frohes Fest
 

Stefan080159

Member
Licensed User
Longtime User
Bluetooth-Autoconnect auf Grundlage von Erel's Bluetooth-Tutorial
will damit nur Strings aus einem anderen Programm empfangen.

B4X:
Sub Class_Globals
 Private AStream As AsyncStreams
 Private serial As Serial
 Private admin As BluetoothAdmin
 Public foundDevices As List
 Type NameAndMac (Name As String, Mac As String)
 Public BluetoothState, ConnectionState As Boolean
 Public Timer1 As Timer
End Sub
Public Sub Initialize
 DateTime .TimeFormat = "hh:mm"
 Timer1.Initialize("timer1",10000)
 Timer1.Enabled = False
 admin.Initialize("admin")
 serial.Initialize("serial")
 If admin.IsEnabled = False Then
  If admin.Enable = False Then
   ToastMessageShow("Fehler beim Verbinden des Bluetooth-Adapters.", True)
  Else
   ToastMessageShow("Verbinde Bluetooth-Adapter...", False)
  End If
 Else
  BluetoothState = True
 End If
End Sub
Private Sub Admin_StateChanged (NewState As Int, OldState As Int)
 Log("Satus gewechselt: " & NewState)
 BluetoothState = NewState = admin.STATE_ON
 NotifyOfStateChanged
End Sub
Public Sub ConnectTo (Device As NameAndMac)
 serial.Connect(Device.Mac)
End Sub
Private Sub Serial_Connected (Success As Boolean)
 Log("Verbunden: " & Success)
 CallSub2(Main, "AfterConnect", Success)
 ConnectionState = Success
 If Success = False Then
  Log(LastException.Message)
  CallSub2(ChatActivity,"NewMessage", DateTime.Time ( DateTime .Now) & " Verbindung unterbrochen...")
  ToastMessageShow("Verbindungsfehler: " & LastException.Message, True)
  Timer1.Enabled = True 
 Else
  If AStream.IsInitialized Then AStream.Close
  AStream.InitializePrefix(serial.InputStream, False, serial.OutputStream, "astream")
  StartActivity(ChatActivity)
  CallSub2(ChatActivity,"NewMessage", DateTime.Time ( DateTime .Now) & " Verbindung hergestellt...")
  ToastMessageShow("Verbindung zu " & Main.Name & " ist Aktiv...", True)
  Timer1.Enabled = False 
 End If
 NotifyOfStateChanged
End Sub
Public Sub SendMessage (msg As String)
 AStream.Write(msg.GetBytes("utf8"))
End Sub
Private Sub AStream_NewData (Buffer() As Byte)
 CallSub2(ChatActivity, "NewMessage", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
Private Sub AStream_Error
 CallSub2(ChatActivity,"NewMessage", DateTime.Time ( DateTime .Now) & " Verbindung unterbrochen...")
 ToastMessageShow("Verbindung zu " & Main.Name & " ist unterbrochen.", True)
 Timer1.Enabled = True
 ConnectionState = False
 NotifyOfStateChanged
End Sub
Private Sub AStream_Terminated
 AStream_Error
End Sub
Public Sub Disconnect
 If AStream.IsInitialized Then AStream.Close
 serial.Disconnect
 End Sub
Public Sub SearchForDevices As Boolean
 foundDevices.Initialize
 Return admin.StartDiscovery
End Sub
Private Sub Admin_DiscoveryFinished
 CallSub(Main, "DiscoverFinished")
End Sub
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
 Log(Name & ":" & MacAddress)
 Dim nm As NameAndMac
 nm.Name = Name
 nm.Mac = MacAddress
 foundDevices.Add(nm)
End Sub
Private Sub NotifyOfStateChanged
 For Each Target In Array(Main, ChatActivity)
  CallSub(Target, "UpdateState")
 Next
End Sub
Sub Timer1_Tick
 If ConnectionState = False Then
  ToastMessageShow("Suche " & Main.Name , True)
  Dim device As NameAndMac = foundDevices.Get(Main.Index1)
  ConnectTo(device)
 Else If ConnectionState = True Then
  If AStream.IsInitialized Then AStream.Close
  AStream.InitializePrefix(serial.InputStream, False, serial.OutputStream, "astream")
  StartActivity(ChatActivity)
 End If
End Sub

Frohe Weihnachten an alle...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…