हाय दोस्तों, मैं ओबैक्स के साथ ब्लूकोव नामक तृतीय पक्ष एपीआई का उपयोग कर एंड्रॉइड डिवाइस से विशिष्ट ब्लूटूथ डिवाइस पर एक फाइल भेजने की कोशिश कर रहा हूं। कनेक्शन हेडर सेट होने पर मैं डिवाइस को कनेक्ट करने में सक्षम हूं, मुझे एक समस्या का सामना करना पड़ रहा है जो सहकर्मी कनेक्शन रीसेट।ब्लूटूथ पीयर कनेक्शन रीसेट
यहां मेरा नीचे कोड स्निपेट है। इस पर कोई मदद की सराहना की।
मेरी गतिविधि में मुझे लगता है कि नीचे फ़ाइल
BlueCoveImpl.setConfigObject(
BlueCoveConfigProperties.PROPERTY_ANDROID_CONTEXT,
this);
String deviceAddress = "0007ABB6D96E";
int channel = 9;
String obexURL = "btgoep://" + deviceAddress + ":"
+ "0000110600001000800000805f9b34fb" + ";android=true";
// String obexURL = "btgoep://" + deviceAddress + ":" + channel
// + ";android=true";
String fileToSend = "sdcard/DSCN9379.jpg";
System.out.println("Connecting to " + obexURL);
FileInputStream stream = new FileInputStream(fileToSend);
File f = new File(fileToSend);
int size = (int) f.length();
byte file[] = new byte[size];
stream.read(file);
String filename = f.getName();
System.out
.println("***************Now sending file to device*****************");
SendFileTask task = new SendFileTask(MainActivity.this, obexURL,
file, filename);
Thread thread = new Thread(task);
thread.start();
================ भेज मैं bluecove कनेक्शन कनेक्ट करने के लिए कोशिश कर रहा हूँ पर कार्रवाई करने के नीचे दिए गए कोड का उपयोग कर रहा निम्नानुसार हेडर सेट के साथ क्लास ऑब्जेक्ट।
package com.example.bluecovesample;
import java.io.OutputStream;
import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.obex.ClientSession;
import javax.obex.HeaderSet;
import javax.obex.Operation;
import javax.obex.ResponseCodes;
//import static write ;
import android.content.Context;
import android.widget.Toast;
public class SendFileTask implements Runnable {
private byte[] file;
private String filename;
public static final int WRITE = 2;
String logString;
int responseCode;
Context context;
String obexURL;
public SendFileTask(Context ctx, String obexUrl, byte[] file,
String filename) {
this.context = ctx;
this.obexURL = obexUrl;
this.file = file;
this.filename = filename;
}
public void run() {
Connection connection = null;
try {
System.out.println(obexURL);
// for (int i = 0; i 3; i++)
{
// connection = Connector.open("btgoep://"+btConnectionURL+
// ":6");
connection = Connector.open(obexURL);
}
// connection obtained
// now, let's create a session and a headerset objects
ClientSession cs = (ClientSession) connection;
HeaderSet hs = cs.createHeaderSet();
// toastMsg(hs.toString());
// now let's send the connect header
// cs.notifyAll();
**cs.connect(hs);**
hs.setHeader(HeaderSet.NAME, filename);
// System.out.println("sfname:"+filename);
int dotIndex = filename.lastIndexOf(".");
// System.out.println("doti:"+dotIndex);
String extension = filename.substring(dotIndex).toLowerCase();
// System.out.println("sfname:"+extension);
if (extension.equals(".txt")) {
hs.setHeader(HeaderSet.TYPE, "text/plain");
} else if (extension.equals(".jpg") || extension.equals(".jpeg")) {
hs.setHeader(HeaderSet.TYPE, "image/jpeg");
} else if (extension.equals(".mpeg") || extension.equals(".mpg")
|| extension.equals(".mp3")) {
hs.setHeader(HeaderSet.TYPE, "video/mpeg");
} else if (extension.equals(".wav")) {
hs.setHeader(HeaderSet.TYPE, "audio/x-wav");
} else if (extension.equals(".3gp")) {
hs.setHeader(HeaderSet.TYPE, "image/jpeg");
} else if (extension.equals("mid") || extension.equals("rmi")) {
hs.setHeader(HeaderSet.TYPE, "audio/mid");
}
hs.setHeader(HeaderSet.LENGTH, new Long(file.length));
Operation putOperation = cs.put(hs);
// System.out.println("response code:"+putOperation.getResponseCode());
// putOperation.getResponseCode();
// this.responseCode = putOperation.getResponseCode();
OutputStream outputStream = putOperation.openOutputStream();
outputStream.write(file);
// file push complete
outputStream.close();
responseCode = putOperation.getResponseCode();
putOperation.close();
cs.disconnect(null);
connection.close();
// file successfully sent
System.out.println("RESPONSE CODE " + responseCode);
if (responseCode == ResponseCodes.OBEX_HTTP_OK) {
System.out.println("FILE SUCCESSFULLY SENT " + filename);
}
else {
System.out.println("FILE SUCCESSFULLY NOT SENT" + filename
+ " not in exception");
}
} catch (Exception e) {
System.out.println("FILE SUCCESSFULLY NOT SENT" + filename
+ " in exception");
// System.out.println("In exception");
e.printStackTrace();
try {
connection.close();
} catch (Exception ex) {
System.out.println("error closing connection" + ex.toString());
}
}
}
private void toastMsg(String msg) {
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
}
ऊपर कोड मैं कनेक्शन गंतव्य डिवाइस में सूचना संवाद स्वीकार मिल गया और उसके बाद क्रियान्वित जबकि अधिसूचित है कि जब तक क्रियान्वित लाइन * cs.connect (एचएस) पर सहकर्मी कनेक्शन बाकी; मेरे logcat में। Logcat स्टैक ट्रेस:
07-11 14: 48: ०७.०४४: डब्ल्यू/System.err (4527): java.io.IOException: सहकर्मी 07-11 से कनेक्शन रीसेट 14: 48: ०७.०५२: डब्ल्यू /System.err(4527): android.bluetooth.BluetoothSocket.readNative (मूल विधि) 07-11 14: 48: 07.059: डब्ल्यू/System.err (4527): android.bluetooth.BluetoothSocket.read (BluetoothSocket.java:336) 07-11 14: 48: ०७.०५९: डब्ल्यू/System.err (4527): android.bluetooth.BluetoothInputStream.read (BluetoothInputStream.java:96 पर) 07-11 14: 48: ०७.०५९ : डब्ल्यू/System.err (4527): com.intel.bluetooth.BluetoothStackAndroid.connectionR पर fRead (BluetoothStackAndroid.java:437) 07-11 14: 48: 07.059: डब्ल्यू/सिस्टम.एर (4527): com.intel.bluetooth.BluetoothRFCommInputStream.read (BluetoothRFCommInputStream.java:139) 07-11 14 : 48: 07.059: डब्ल्यू/सिस्टम.एर (4527): com.intel.bluetooth.obex.OBEXUtils.readFully (OBEXUtils.java:71) 07-11 14: 48: 07.059: डब्ल्यू/System.err (4527): 48:: ०७.०५९: डब्ल्यू/System.err (4527): com.intel.bluetooth पर com.intel.bluetooth.obex.OBEXSessionBase.readPacket (OBEXSessionBase.java:217) 07-11 14 पर। obex.OBEXClientSessionImpl.connectImpl (OBEXClientSessionImpl.java:100) 07-11 14: 48: 07.059: डब्ल्यू/System.err (4527): com.intel.bluetooth.obex.OBEXClientSessionImpl.connect (OBEXClientSessionImpl.java:85) 07-11 14: 48: 07.059: डब्ल्यू/सिस्टम.एर (4527): com.example.bluecovesample.SendFileTask.run (SendFileTask.java:78) 07-11 14: 48: 07.059: डब्ल्यू/सिस्टम .err (4527): java.lang.Thread.run (Thread.java:1019)
... मैं कनेक्ट करने में सक्षम कर सकते हैं लेकिन जब मैं cs.connect (एचएस) तक पहुँचने; फ़ाइल भेजने के लिए कनेक्टेड डिवाइस के लिए हेडरसेट सेट करने का प्रयास कर रहा है, यह डिस्कनेक्ट हो जाता है। इसके लिए अन्य solutin। –
क्या आपके पास अपने मैनिफेस्ट में READ_EXTERNAL_STORAGE और BLUETOOTH अनुमतियां हैं? – Erol
यदि हां, तो यहां स्रोत कोड देखें: http://gitorious.org/android-obex और अपने कोड की तुलना करें। – Erol