कुछ समय पहले मैं एक ऐसी ही कोशिश कर एंड्रॉयड फोन के लिए एक ब्लूटूथ डिवाइस से कनेक्ट समस्या थी। यद्यपि आपकी डिवाइस प्रोफ़ाइल अलग है, मुझे लगता है कि समाधान वही है।
package android.bluetooth;
import android.bluetooth.BluetoothDevice;
/**
* System private API for Bluetooth A2DP service
*
* {@hide}
*/
interface IBluetoothA2dp {
boolean connectSink(in BluetoothDevice device);
boolean disconnectSink(in BluetoothDevice device);
boolean suspendSink(in BluetoothDevice device);
boolean resumeSink(in BluetoothDevice device);
BluetoothDevice[] getConnectedSinks();
BluetoothDevice[] getNonDisconnectedSinks();
int getSinkState(in BluetoothDevice device);
boolean setSinkPriority(in BluetoothDevice device, int priority);
int getSinkPriority(in BluetoothDevice device);
boolean connectSinkInternal(in BluetoothDevice device);
boolean disconnectSinkInternal(in BluetoothDevice device);
}
फिर, उन कार्यक्षमताओं तक पहुँचने के लिए, निम्नलिखित वर्ग अपनी परियोजना में डाल:
सबसे पहले आप android.bluetooth
नामित अपनी परियोजना में एक पैकेज बना सकते हैं और निम्नलिखित IBluetoothA2dp.aidl वहाँ में डाल की जरूरत है
public class BluetoothA2dpConnection {
private IBluetoothA2dp mService = null;
public BluetoothA2dpConnection() {
try {
Class<?> classServiceManager = Class.forName("android.os.ServiceManager");
Method methodGetService = classServiceManager.getMethod("getService", String.class);
IBinder binder = (IBinder) methodGetService.invoke(null, "bluetooth_a2dp");
mService = IBluetoothA2dp.Stub.asInterface(binder);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public boolean connect(BluetoothDevice device) {
if (mService == null || device == null) {
return false;
}
try {
mService.connectSink(device);
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
return true;
}
public boolean disconnect(BluetoothDevice device) {
if (mService == null || device == null) {
return false;
}
try {
mService.disconnectSink(device);
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
return true;
}
}
अंत में, अपने A2DP डिवाइस कनेक्ट करने के लिए, एक ब्लू लेने युग्मित डिवाइस की सूची से etoothDevice और इसे connect
विधि के पैरामीटर के रूप में भेजें। सही प्रोफ़ाइल वाला डिवाइस चुनना सुनिश्चित करें, अन्यथा आपके पास अपवाद होगा।
मैंने एंड्रॉइड संस्करण 2.3 के साथ इस फोन का परीक्षण किया है और यह ठीक काम करता है।
क्षमा करें कोई भी अंग्रेजी गलती। मैं आशा करता हूं यह आपकी मदद कर सकते हैं।
यह कौन सा फोन है, डिवाइस की नेक्सस लाइन पर सेटिंग मौजूद है? – nandeesh
मैं जिस फोन का उपयोग कर रहा हूं वह गैलेक्सी एस 3 डब्ल्यू/एटी एंड टी है। मैं यह सुनिश्चित नहीं कर सकता कि यह वहां मौजूद होगा, लेकिन मुझे लगता है कि यह होगा। – JamesB41