Ben bir android cihazdan 'a' gibi basit bir dize veri bluetooth üzerinden diğerine göndermek istiyorum. Ben android sdk örnek bluetooth kodu baktım ama benim için çok karmaşık. Bir düğmeye bastığımda sadece belirli verileri nasıl gönderebileceğimi anlayamıyorum. Bu sorunu nasıl çözebilirim?Android örnek bluetooth kodu bluetooth üzerinden basit bir dize göndermek için
cevap
private OutputStream outputStream;
private InputStream inStream;
private void init() throws IOException {
BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();
if (blueAdapter != null) {
if (blueAdapter.isEnabled()) {
Set<BluetoothDevice> bondedDevices = blueAdapter.getBondedDevices();
if(bondedDevices.size() > 0) {
Object[] devices = (Object []) bondedDevices.toArray();
BluetoothDevice device = (BluetoothDevice) devices[position];
ParcelUuid[] uuids = device.getUuids();
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());
socket.connect();
outputStream = socket.getOutputStream();
inStream = socket.getInputStream();
}
Log.e("error", "No appropriate paired devices.");
} else {
Log.e("error", "Bluetooth is disabled.");
}
}
}
public void write(String s) throws IOException {
outputStream.write(s.getBytes());
}
public void run() {
final int BUFFER_SIZE = 1024;
byte[] buffer = new byte[BUFFER_SIZE];
int bytes = 0;
int b = BUFFER_SIZE;
while (true) {
try {
bytes = inStream.read(buffer, bytes, BUFFER_SIZE - bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Teşekkür anlamlara gelebilir. Buna ek olarak, bu mesajı başka cihazdan nasıl alabilirim? – user3374956
@ user3374956 genel olarak "InputStream" kaynağındaki verileri okumalısınız. Veriler nasıl gönderilir göndericiye bağlıdır. Kodu güncelledim. – eleven
gerekli izinler nelerdir? – Prasad
- 1. MIDI Bluetooth Üzerinden
- 2. BlueTooth aracılığıyla bir dize nasıl gönderilir/gönderilir
- 3. Bluetooth Sohbetini Değiştir Android olmayan Aygıtlarla bağlanmak için Örnek Kod
- 4. Android Bluetooth SPP Sunucusu
- 5. gönder/G/göndermek bir android cihazdan bir dize almaya çalışıyorum Bluetooth
- 6. bluetooth
- 7. Bluetooth terminali üzerinden RFCOMM Bluetooth'a erişin
- 8. android bluetooth bağlanamıyor
- 9. Android Bluetooth dosya gönderirken sorun
- 10. Android 2.1: Bluetooth Şifreleme
- 11. Bluetooth üzerinden diğer iPhone'lara nasıl dosya gönderilir
- 12. Android Bluetooth Bağlantı Hatası
- 13. Android Bluetooth Discovery çalışmıyor
- 14. Android Bluetooth bağlantı sorunu
- 15. Android Bluetooth COM bağlantı noktası
- 16. Android bluetooth kullanarak dosya gönder?
- 17. android üzerindeki bluetooth soketine bağlanamıyor
- 18. Android cihazında Bluetooth ayarları Bluetooth cihazından nasıl alınır?
- 19. Android Bluetooth Keşif İletişim Kutusu
- 20. Android Bluetooth Düşük Energie Servis
- 21. Android Bluetooth Eşleştirme İletişimini Önleyin
- 22. Debian: Bluetooth üzerinden ileri giriş konsolu
- 23. Android Bluetooth soketi donma uygulaması
- 24. Android Bluetooth hayatı kolaylaştıran kütüphaneler?
- 25. gönderme veri Bluetooth Modülü HC-05 aracılığıyla bir Android uygulaması için arduino veri göndermek için çalışıyorlar
- 26. Android'de Bluetooth SPP'yi etkinleştirin mi?
- 27. Bir bluetooth aksesuarı simüle eden basit bir uygulama
- 28. Yalnızca Bluetooth Seçenekleriyle Paylaşım Hedefi
- 29. Bluetooth ve delphi, nasıl?
- 30. Bluetooth Otomatik Bağlantı
Ayrıca [buradan] senin relpy için (https://stackoverflow.com/questions/13450406/how-to-receive-serial-data-using-android-bluetooth) –