Android的BluetoothPAN创建的Andr​​oid设备和Windows7 PC的TCP / IP网络设备、网络、Andr、oid

2023-09-04 03:46:53 作者:ゐ尔守侯

问题1)我想创建的Andr​​oid设备,并在Windows 7 PC上的TCP / IP连接。为此,我使用Java反射API使用Android的隐藏BlutoothPan类。这里是code:

Question 1) I'm trying to create a TCP/IP connection between Android device and a Windows 7 PC. For this purpose, I'm using Android's hidden BlutoothPan class using Java reflection API. Here is the code:

private void invokeConnectMehotd() {

    String sClassName = "android.bluetooth.BluetoothPan";

    try {  

        Class<?> classBluetoothPan = Class.forName(sClassName);

        Constructor<?> ctor = classBluetoothPan.getDeclaredConstructor(Context.class, ServiceListener.class);
        ctor.setAccessible(true);
        Object instance = ctor.newInstance(mContext, mServiceListener);                 

        if(mPairedBluetoothDevice != null) {

            //  Set Tethering ON
            Class[] paramSet = new Class[1];
            paramSet[0] = boolean.class;

            Method setTetheringOn = classBluetoothPan.getDeclaredMethod("setBluetoothTethering", paramSet);

            setTetheringOn.invoke(instance, true);

            //  IsTetheringOn?
            Class<?> noparams[] = {};

            Method m = classBluetoothPan.getDeclaredMethod("isTetheringOn", noparams);
            boolean isTetheringOn = ((Boolean) m.invoke(instance, (Object []) noparams)).booleanValue();           

            Log.d("Tether", "Tethered = "+ isTetheringOn);


            //  Connect to remote device
            Class[] paramDevice = new Class[1];
            paramDevice[0] = BluetoothDevice.class;

            Method connect = classBluetoothPan.getDeclaredMethod("connect", paramDevice);

            boolean isConnected = ((Boolean) connect.invoke(instance, mPairedBluetoothDevice)).booleanValue();
            Log.d("Connected", "Connected = "+ isConnected);
        }

    } catch (ClassNotFoundException e) {  
        e.printStackTrace();
    } catch (SecurityException e) {  
        e.printStackTrace();
    } catch (Exception e) {  
        e.printStackTrace();
    }  
}

下面是日志从logcat的:

Here is the log from logcat:

07-16 23:04:04.514: D/GLWebViewState(8937): Reinit shader
07-16 23:04:04.604: D/GLWebViewState(8937): Reinit transferQueue
07-16 23:04:12.452: E/QLBluetoothServer(8937): L-AV-SUDGUDI01
07-16 23:04:12.452: E/QLBluetoothServer(8937): E0:2A:82:2C:6E:E0
07-16 23:04:14.123: E/QLBluetoothServer(8937): HPTEST-PC
07-16 23:04:14.123: E/QLBluetoothServer(8937): 00:27:13:DC:AB:FD
07-16 23:04:18.608: D/BluetoothPan(8937): BluetoothPan() call bindService
07-16 23:04:18.628: D/BluetoothPan(8937): BluetoothPAN Proxy object connected
07-16 23:04:18.638: D/BluetoothPan(8937): BluetoothPan(), bindService called
07-16 23:04:19.318: D/BluetoothPan(8937): setBluetoothTethering(true)
07-16 23:04:19.328: D/BluetoothPan(8937): isTetheringOn()
07-16 23:04:19.338: D/Tether(8937): Tethered = true
07-16 23:04:20.469: D/BluetoothPan(8937): connect(E0:2A:82:2C:6E:E0)
07-16 23:04:20.529: D/Connected(8937): Connected = true

尽管日志说,该设备连接到Win7的电脑,我还没有看到IP分配给我的电脑从设备,也没有我的电脑可以通过我的Andr​​oid设备的3G / 4G网络来访问因特网。

Even though the log says, the device is connected to Win7 PC, I still don't see IP Assigned to my PC from the device nor my PC can access Internet through 3G/4G network of my Android device.

请建议,如果这是建立TCP / IP上的蓝牙?正确的方法

Please suggest if this is the correct method to establish TCP/IP over Bluetooth?

问题2)我也试图从Win7的电脑连接到Android设备。但我没有发现任何的Win32 API来Win7的电脑上访问蓝牙模式。我也试图在UI自动化Win7上调用控制面板程序的个性化应用程序(比如,我希望通过编程模拟,以右键单击我的设备上 - >连接方式 - >接入点)。

Question 2) I'm also trying to connect from Win7 PC to Android device. But I didn't find any Win32 APIs to access Bluetooth profiles on Win7 PC. I also tried to automate the UI on Win7 to invoke Control Panel applet's individual Application (Say, I want to mimic programatically to right click on my device -> Connect Using -> Access Point).

请说明是否有任何方法或者编程访问控制面板小程序的各个项目,并在其上​​调用操作或使用API​​从Win7的PC建立TCP / IP通过蓝牙。

Please suggest if there are any methods to either programatically access Control Panel applet's individual items and invoke operations on them or using APIs to establish TCP/IP over Bluetooth from Win7 PC.

任何帮助是非常AP preciated。

Any help is highly appreciated.

推荐答案

请检查该库 http://bluecove.org/ 。这可能是解决你的问题。

please check this library http://bluecove.org/. It may be solve your problem.