RESULT_OK 无法解析为变量
RESULT_OK cannot be resolved to a variable
我对此行有问题,我正在尝试使用处理为 android 创建一个应用程序,我是 android 的新手。
这是我的代码:
@Override
public void onActivityResult(int requestCode, int resultCode,Intent data){
if(requestCode==0){
if(resultCode == RESULT_OK){
BACKGND=2; //Set the background to GREEN
} else {
BACKGND=1; //Set the background to RED
}
}
}
我收到以下错误:
1. ERROR in /tmp/android6837327122296929778sketch/src/processing/test/sketch_151209a/sketch_151209a.java (at line 52)
if(resultCode == RESULT_OK){
^^^^^^^^^
RESULT_OK cannot be resolved to a variable
///////更新////////
完整代码如下:
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
int BACKGND=0; //Set the background to BLUE
//Get the default Bluetooth adapter
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
/*The startActivityForResult() launches an Activity which is
used to request the user to turn Bluetooth on.
The following onActivityResult() method is called when the
Activity exits. */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode==0){
if(resultCode == Activity.RESULT_OK){
BACKGND=2; //Set the background to GREEN
} else {
BACKGND=1; //Set the background to RED
}
}
}
void setup(){
orientation(LANDSCAPE);
/*IF Bluetooth is NOT enabled,
then ask user permission to enable it */
if (!bluetooth.isEnabled()) {
Intent requestBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(requestBluetooth, 0);
}
}
void draw(){
if(BACKGND==0){
background(10,10,255); //Set background to BLUE
} else if(BACKGND==1) {
background(255,10,10); //Set background to RED
} else {
background(10,255,10); //Set background to GREEN
}
}
RESULT_OK
是Activityclass的常量。如果此代码在片段中执行,则不会解析变量。
参考如下:
Activity.RESULT_OK
我对此行有问题,我正在尝试使用处理为 android 创建一个应用程序,我是 android 的新手。 这是我的代码:
@Override
public void onActivityResult(int requestCode, int resultCode,Intent data){
if(requestCode==0){
if(resultCode == RESULT_OK){
BACKGND=2; //Set the background to GREEN
} else {
BACKGND=1; //Set the background to RED
}
}
}
我收到以下错误:
1. ERROR in /tmp/android6837327122296929778sketch/src/processing/test/sketch_151209a/sketch_151209a.java (at line 52)
if(resultCode == RESULT_OK){
^^^^^^^^^
RESULT_OK cannot be resolved to a variable
///////更新////////
完整代码如下:
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
int BACKGND=0; //Set the background to BLUE
//Get the default Bluetooth adapter
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
/*The startActivityForResult() launches an Activity which is
used to request the user to turn Bluetooth on.
The following onActivityResult() method is called when the
Activity exits. */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode==0){
if(resultCode == Activity.RESULT_OK){
BACKGND=2; //Set the background to GREEN
} else {
BACKGND=1; //Set the background to RED
}
}
}
void setup(){
orientation(LANDSCAPE);
/*IF Bluetooth is NOT enabled,
then ask user permission to enable it */
if (!bluetooth.isEnabled()) {
Intent requestBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(requestBluetooth, 0);
}
}
void draw(){
if(BACKGND==0){
background(10,10,255); //Set background to BLUE
} else if(BACKGND==1) {
background(255,10,10); //Set background to RED
} else {
background(10,255,10); //Set background to GREEN
}
}
RESULT_OK
是Activityclass的常量。如果此代码在片段中执行,则不会解析变量。
参考如下:
Activity.RESULT_OK