के माध्यम से एक साधारण स्ट्रिंग भेजने के लिए एंड्रॉइड नमूना ब्लूटूथ कोड मैं एक एंड्रॉइड डिवाइस से 'ए' ब्लूटूथ के माध्यम से एक सरल स्ट्रिंग डेटा भेजना चाहता हूं। मैंने एंड्रॉइड एसडीके में नमूना ब्लूटूथ कोड देखा लेकिन यह मेरे लिए इतना जटिल है। जब मैं बटन दबाता हूं तो मैं समझ नहीं पा रहा हूं कि मैं केवल विशिष्ट डेटा कैसे भेज सकता हूं। इस समस्या का समाधान किस प्रकार से किया जा सकता है?ब्लूटूथ
ब्लूटूथ
उत्तर
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();
}
}
}
अपने relpy के लिए धन्यवाद। इसके अलावा, मैं यह संदेश अन्य डिवाइस से कैसे प्राप्त कर सकता हूं? – user3374956
@ user3374956 सामान्य रूप से आपको 'इनपुटस्ट्रीम' से डेटा पढ़ने की आवश्यकता है। डेटा प्राप्त करने के लिए प्रेषक पर निर्भर करता है। मैंने कोड अपडेट किया है। – eleven
अनुमोदन आवश्यक हैं? – Prasad
- 1. ब्लूटूथ
- 2. ब्लूटूथ
- 3. ब्लूटूथ
- 4. ब्लूटूथ
- 5. ब्लूटूथ
- 6. ब्लूटूथ
- 7. ब्लूटूथ
- 8. ब्लूटूथ
- 9. ब्लूटूथ
- 10. ब्लूटूथ
- 11. ब्लूटूथ प्रोटोकॉल?
- 12. ब्लूटूथ सिग्नल
- 13. ब्लूटूथ: ब्लूज़
- 14. एंड्रॉइड ब्लूटूथ
- 15. ब्लूटूथ प्रसारण
- 16. ब्लूटूथ 3.0
- 17. ब्लूटूथ/वाईफाई
- 18. ब्लूटूथ इनबॉक्स
- 19. एंड्रॉइड: ब्लूटूथ
- 20. ब्लूटूथ कीबोर्ड
- 21. आईफोन - ब्लूटूथ
- 22. एंड्रॉइड ब्लूटूथ
- 23. ब्लूटूथ हेडसेट
- 24. ब्लूटूथ दोस्त
- 25. रिमोट ब्लूटूथ
- 26. ब्लूटूथ स्पीकर
- 27. ब्लूटूथ एंड्रॉइड
- 28. ब्लूटूथ पिंग लेटेंसी
- 29. ब्लूटूथ फ़ाइल स्थानांतरण
- 30. आईफोन ब्लूटूथ संचार उदाहरण
आप [यहां] उल्लेख कर सकते हैं भी (https://stackoverflow.com/questions/13450406/how-to-receive-serial-data-using-android-bluetooth) –