无法解析符号“ REQUEST_ENABLE_BLUETOOTH”

夏尔·夏尔马

我正在尝试实现一项功能,该功能检查是否启用了蓝牙。我不断得到:无法解析符号“ 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);
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章