package com.whyc.lock;
|
|
import com.getcapacitor.BridgeActivity;
|
// public class MainActivity extends BridgeActivity {}
|
|
import android.os.Bundle; // 添加这个导入语句
|
import android.bluetooth.BluetoothAdapter;
|
import android.content.Intent;
|
|
public class MainActivity extends BridgeActivity {
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
// 打开安卓系统蓝牙
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
|
Intent enableBluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
startActivityForResult(enableBluetoothIntent, REQUEST_ENABLE_BT);
|
}
|
|
}
|
|
@Override
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
super.onActivityResult(requestCode, resultCode, data);
|
if (requestCode == REQUEST_ENABLE_BT && resultCode == RESULT_OK) {
|
// 安卓系统蓝牙已打开
|
} else if (requestCode == REQUEST_ENABLE_BT && resultCode == RESULT_CANCELED) {
|
// 用户取消打开安卓系统蓝牙
|
}
|
}
|
|
private static final int REQUEST_ENABLE_BT = 1;
|
}
|