Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用“创建BluetoothSocket崩溃”;无法执行“活动”的方法;_Android_Sockets_Bluetooth - Fatal编程技术网

Android 使用“创建BluetoothSocket崩溃”;无法执行“活动”的方法;

Android 使用“创建BluetoothSocket崩溃”;无法执行“活动”的方法;,android,sockets,bluetooth,Android,Sockets,Bluetooth,结果: E/AndroidRuntime(14079):java.lang.IllegalStateException:无法执行活动的方法 同一方法中“socket=”语句前面的语句执行良好。使用getName()获取设备似乎可以正常工作。 它运行的物理设备具有API 8 蓝牙开发指南隐晦地说: long uuidHigh = new BigInteger("11bc4f7154ac9edb", 16).longValue(); long uuidLow = new BigInteger("1

结果:
E/AndroidRuntime(14079):java.lang.IllegalStateException:无法执行活动的方法

同一方法中“socket=”语句前面的语句执行良好。使用getName()获取设备似乎可以正常工作。 它运行的物理设备具有API 8

蓝牙开发指南隐晦地说:

long uuidHigh = new BigInteger("11bc4f7154ac9edb", 16).longValue();
long uuidLow =  new BigInteger("167bf05f9436bc0a", 16).longValue();
UUID uuid = new UUID(uuidHigh, uuidLow);

BluetoothSocket socket = null;
BluetoothAdapter blueAdapter = null;

blueAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = blueAdapter.getRemoteDevice("00:07:AB:6A:96:7D");

try {
    socket = device.createRfcommSocketToServiceRecord(uuid); // CRASH!
} catch (IOException e) { e.printStackTrace(); }
但是createRfcommSocketToServiceRecord()不能接受字符串,它必须接受UUID

舱单:

    // MY_UUID is the app's UUID string, also used by the server code
    tmp = device.createRfcommSocketToServiceRecord(MY_UUID);


当您弄乱清单或xml时,这种情况非常常见。你能把它也贴出来吗?增加了舱单。很简单,我应该“关闭”什么吗?我之前因为另一个原因崩溃了,可能是蓝牙被屏蔽了?但是discovery()工作得很好。也许它与操作系统切换活动有关。LogCat说,它过去常常时不时地运行“InputMethodManager”,但代码在按下按钮和崩溃之间运行良好。当logcat崩溃时,它在我的活动中。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="intrax.demo.explore"
    android:versionCode="1" android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
        <activity
            android:name=".BluetoothAct" android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        </application>

</manifest>