0

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();
            }
     }
}
}
  • did you solve this? I have problems with pulling data not pushing. it keep asking for login/password even though its public data. how do you access your data? @Daniel Wennberg – Celly Jun 08 '15 at 13:51
  • I did solve it. my problem was as i expected that i did not format my pull Json correctly. have you implemented the feed id and key in your request? – Daniel Wennberg Aug 28 '15 at 21:52

0 Answers0