我的java代码请看下面:
package com.example.user.firebase;
public class MainActivity extends ActionBarActivity {
private Firebase mRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
}
@Override
protected void onStart(){
super.onStart();
Button mbuttonHigh = (Button) findViewById(R.id.buttonHigh);
Button mbuttonLow = (Button) findViewById(R.id.buttonLow);
final TextView mtextViewCondition = (TextView) findViewById(R.id.textViewCondition);
mRef = new Firebase("https://myfire.firebaseio.com/light/GPIO");
mbuttonLow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRef.setValue("0");
}
});
mbuttonHigh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRef.setValue("1");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我可以向我的火力基地发送“0”或“1”。但我不知道为什么我的设备(ARM coretex M3 EVB)无法获取数据。
当我使用HTML时,我的设备(ARM coretex M3 EVB)可以获取数据。我的HTML代码请参见下文:
var myDataRef = new Firebase('https://myfirebase.firebaseio.com/light');
function high(){
var gpio = "1";
myDataRef.set({
GPIO: gpio,
});
};
function low(){
var gpio = "0";
myDataRef.set({
GPIO: gpio,
});
};
这两种方式都可以正常发送到firebase。我不知道为什么我的设备(ARM coretex M3)无法通过java获取数据。 java的setvale()和html是否设置不同?
非常感谢你。 :d