我正在尝试实现一项功能,该功能检查是否启用了蓝牙。我不断得到:无法解析符号“ 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);
}
}
}
答案 0 :(得分:1)
按如下所示初始化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);
}
}
}