Android : Healthvault_putting data

on Thursday, August 21, 2014


Hi I am trying to add a new wEIGHT value to healthvault When I used the code provided with SDK its wrkng fine I splitted the code to use with another UI.Now its giving me errors Logcat is showng No errors. Error message is "An exception occured:null"


This is my code



import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.customlist.R;
import com.microsoft.hsg.Request;
import com.microsoft.hsg.android.HealthVaultService;


import com.microsoft.hsg.android.demo.hv.Weight;
import com.microsoft.hsg.request.SimpleRequestTemplate;

public class AddWeight extends Activity {

private HealthVaultService service;
// private Record selectedRecord;
String recd_id = "";
String persn_id = "";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addweight);
service = HealthVaultService.getInstance();
Intent intent = getIntent();
recd_id = intent.getExtras().getString("recd_id");
persn_id = intent.getExtras().getString("persn_id");
Button save = (Button) findViewById(R.id.savebutton);
save.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText text = (EditText) findViewById(R.id.edt_wght);
PutWeight putAction = new PutWeight(text.getText().toString());
putAction.execute();
}
});


Button backpage = (Button) findViewById(R.id.backbutton);
backpage.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
service.reset();
Intent i = new Intent(AddWeight.this,WeightActivity.class);
startActivity(i);
finish();
}
});


}



private class PutWeight extends AsyncTask<Void, Void, Void> {
private String weight;
private Exception exception;
ProgressDialog progressDialog;


public PutWeight(String weight) {
this.weight = weight;
progressDialog = ProgressDialog.show(
AddWeight.this,
"",
"Saving Data",
true);
}


protected Void doInBackground(Void... v) {
try {

putWeight(weight);
} catch(Exception e) {
exception = e;
}

return null;
}

/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(Void v) {
progressDialog.dismiss();

if (exception == null) {
Intent i=new Intent(AddWeight.this,WeightActivity.class);
startActivity(i);
finish();
} else {
Toast.makeText(
AddWeight.this,
"An error occurred. " + exception.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}
private void putWeight(String value)
{
Weight weight = new Weight(Double.parseDouble(value));

SimpleRequestTemplate template = new SimpleRequestTemplate(
service.getConnection(),
persn_id,
recd_id);

StringBuilder infoBuilder = new StringBuilder();
infoBuilder.append("<info><thing><type-id>");
infoBuilder.append(Weight.TYPE);
infoBuilder.append("</type-id><data-xml>");
infoBuilder.append(weight.toXml());
infoBuilder.append("<common/></data-xml></thing></info>");

Request request = new Request();
request.setMethodName("PutThings");
request.setInfo(infoBuilder.toString());
template.makeRequest(request);
}
}

0 comments:

Post a Comment