gpt4 book ai didi

android - 无法解析符号 'REQUEST_ENABLE_BLUETOOTH'

转载 作者:行者123 更新时间:2023-11-29 01:01:18 31 4
gpt4 key购买 nike

我正在尝试实现一项检查蓝牙是否已启用的功能。我不断收到:无法解析符号“REQUEST_ENABLE_BLUETOOTH”。我是 Java 初学者,刚开始在 Android Studio 中从事实习项目。

package achal.xylotron.com.bluespot;

import android.app.Activity;
import android.os.Bundle;
import android.bluetooth.*;
import android.content.Intent;

public class BlueChat extends Activity
{

BluetoothAdapter bluetoothAdapter;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.blue_chat);

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (!bluetoothAdapter.isEnabled())
{
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BLUETOOTH);
}
}
}

最佳答案

像下面这样初始化 REQUEST_ENABLE_BLUETOOTH int

package achal.xylotron.com.bluespot;

import android.app.Activity;
import android.os.Bundle;
import android.bluetooth.*;
import android.content.Intent;

public class BlueChat extends Activity
{

BluetoothAdapter bluetoothAdapter;
int REQUEST_ENABLE_BLUETOOTH = 0;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.blue_chat);

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (!bluetoothAdapter.isEnabled())
{
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BLUETOOTH);
}
}
}

关于android - 无法解析符号 'REQUEST_ENABLE_BLUETOOTH',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50948225/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com