【发布时间】:2015-12-09 17:14:42
【问题描述】:
我的这条线有问题,我正在尝试使用处理创建一个适用于 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
}
}
【问题讨论】:
-
onActivityResult 声明在哪里?片段还是活动?
标签: android bluetooth arduino processing