• 大小: 81KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-09
  • 语言: Java
  • 标签: 手机app  源码  继电器  

资源简介

手机蓝牙 控制继电器,修改后可以作为,手机控制单片机小车

资源截图

代码片段和文件信息

package edu.stanford.mobisocial.bluetooth;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;

public class InsecureBluetooth {
static private class InUse extends RuntimeException {
}
public static BluetoothServerSocket listenUsingRfcommWithServiceRecord(BluetoothAdapter adapter String name UUID uuid boolean encrypt) throws IOException {
     try {
Class c_rfcomm_channel_picker = null;
Class[] children = BluetoothAdapter.class.getDeclaredClasses();
for(Class c : children) {
Log.e(“TO“ “class “ + c.getCanonicalName());
if(c.getCanonicalName().equals(BluetoothAdapter.class.getName() + “.RfcommChannelPicker“)) {
c_rfcomm_channel_picker = c;
break;
}
}
if(c_rfcomm_channel_picker == null)
     throw new RuntimeException(“can‘t find the rfcomm channel picker class“);
    
     Constructor constructor = c_rfcomm_channel_picker.getDeclaredConstructor(UUID.class);
     if(constructor == null)
     throw new RuntimeException(“can‘t find the constructor for rfcomm channel picker“);
     object rfcomm_channel_picker = constructor.newInstance(new object[] {uuid});
     Method m_next_channel = c_rfcomm_channel_picker.getDeclaredMethod(“nextChannel“ new Class[] {});
     m_next_channel.setAccessible(true);
    
BluetoothServerSocket socket = null;
    
int channel;
int errno;
while (true) {
    channel = (Integer)m_next_channel.invoke(rfcomm_channel_picker new object[] {});

    if (channel == -1) {
        throw new IOException(“No available channels“);
    }

    try {
     socket = listenUsingRfcomm(channel encrypt);
     break;
    } catch(InUse e) {
     continue;
    }
}

     Field f_internal_service = adapter.getClass().getDeclaredField(“mService“);
     f_internal_service.setAccessible(true);
     object internal_service = f_internal_service.get(adapter);
    
     Method m_add_rfcomm_service_record = internal_service.getClass().getDeclaredMethod(“addRfcommServiceRecord“ new Class[] {String.class ParcelUuid.class int.class IBinder.class});
     m_add_rfcomm_service_record.setAccessible(true);

     int handle = (Integer)m_add_rfcomm_service_record.invoke(internal_service new object[] { name new ParcelUuid(uuid) channel new Binder() } );

if (handle == -1) {
    try {
        socket.close();
    } catch (IOException e) {}
    throw new IOException(“Not able to register SDP record for “ + name);
}
     Field f_intern

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-08-27 21:51  testBlueTooth\
     文件         475  2014-08-27 21:51  testBlueTooth\.classpath
     文件         849  2010-11-21 17:17  testBlueTooth\.project
     目录           0  2014-08-27 21:51  testBlueTooth\.settings\
     文件         177  2014-08-27 21:51  testBlueTooth\.settings\org.eclipse.jdt.core.prefs
     文件         875  2012-10-13 16:25  testBlueTooth\AndroidManifest.xml
     目录           0  2014-08-28 16:50  testBlueTooth\bin\
     文件         875  2014-08-28 15:20  testBlueTooth\bin\AndroidManifest.xml
     目录           0  2014-08-28 15:20  testBlueTooth\bin\classes\
     文件       25068  2014-08-28 16:50  testBlueTooth\bin\classes.dex
     目录           0  2014-08-28 15:20  testBlueTooth\bin\classes\com\
     目录           0  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\
     文件         343  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\BuildConfig.class
     文件         337  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R$attr.class
     文件         397  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R$drawable.class
     文件        1472  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R$id.class
     文件         427  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R$layout.class
     文件         424  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R$string.class
     文件         524  2014-08-28 15:49  testBlueTooth\bin\classes\com\testBlueTooth\R.class
     文件        2684  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\RelayControl$ClickEvent.class
     文件        3014  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\RelayControl$ConnectedThread$ReadRunnable.class
     文件        1941  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\RelayControl$ConnectedThread.class
     文件        1330  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\RelayControl$MyHandler.class
     文件        6578  2014-08-28 15:20  testBlueTooth\bin\classes\com\testBlueTooth\RelayControl.class
     文件        2558  2014-08-28 16:50  testBlueTooth\bin\classes\com\testBlueTooth\testBlueTooth$1.class
     文件        2685  2014-08-28 16:50  testBlueTooth\bin\classes\com\testBlueTooth\testBlueTooth$AcceptThread.class
     文件        3311  2014-08-28 16:50  testBlueTooth\bin\classes\com\testBlueTooth\testBlueTooth$ClickEvent.class
     文件        4542  2014-08-28 16:50  testBlueTooth\bin\classes\com\testBlueTooth\testBlueTooth$ItemClickEvent.class
     文件        6073  2014-08-28 16:50  testBlueTooth\bin\classes\com\testBlueTooth\testBlueTooth.class
     目录           0  2014-08-28 16:48  testBlueTooth\bin\dexedLibs\
     文件         910  2014-08-28 16:48  testBlueTooth\bin\dexedLibs\annotations-2b9df868312cd1defc406a7a5f598252.jar
............此处省略32个文件信息

评论

共有 条评论