I want to be able to both read and write to xively from my phone. its a simple exchange of data. i.e, player one gives data A to player B and vice verse. i am able to pull data from xively but im a bit confused how to push to JSONObject(1) while reviving JSONObject(0) etc. here is were im at right now in my test environment:
public class MainActivity extends Activity {
TextView thevalue;
Button getJson;
private static String url = "https://api.xively.com/v2/feeds/id and key";
JSONArray user = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getJson = (Button)findViewById(R.id.getdata);
getJson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new JSONParse().execute();
}
});
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
thevalue = (TextView)findViewById(R.id.value);
}
@Override
protected JSONObject doInBackground(String... args) {
getJson theParser = new getJson();
JSONObject json = theParser.doIt(url);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
user = json.getJSONArray("datastreams");
JSONObject c = user.getJSONObject(0);
String curval = c.getString("current_value");
Log.i("JSONARR", user.toString());
thevalue.setText(curval);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}