A bit of background: I am using Samsung Gear 2, Samsung s4 ,Eclipse and Tizen IDE for Wearable.
I have an app on both devices that communicates using Accessory SDK. On the same app, I also have codes that read the heartrate. I pass the heartrate from the wear app using SASocket.sendData on the code below. I access the string on the android app using onRecieve method which is also on shown below.
Now, I want to save the heartrate in Mysql. How can I access the String and save it to Mysql?
try {
SASocket.setDataReceiveListener(onreceive);
SASocket.sendData(CHANNELID,heartrate.toString());
} catch(err) {
console.log("exception [" + err.name + "] msg[" + err.message + "]");
}
@Override
public void onReceive(int channelId, byte[] data) {
Log.d(TAG, "onReceive");
Time time = new Time();
time.set(System.currentTimeMillis());
String timeStr = " " + String.valueOf(time.minute) + ":"
+ String.valueOf(time.second);
String strToUpdateUI = new String(data);
System.out.println("strToUpdateUI : " + strToUpdateUI);
heartrate =strToUpdateUI;
final String message = strToUpdateUI.concat(timeStr);
final HelloAccessoryProviderConnection uHandler = mConnectionsMap.get(Integer
.parseInt(String.valueOf(mConnectionId)));
if(uHandler == null){
Log.e(TAG,"Error, can not get HelloAccessoryProviderConnection handler");
return;
}
new Thread(new Runnable() {
public void run() {
try {
uHandler.send(HELLOACCESSORY_CHANNEL_ID, message.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
First of all, it's great that you have come this far in your Gear App development i.e. getting your provider and consume side apps to communicate. Most of the hard work is already done. I assume that you successfully have your heart rate data in your heartrate variable heartrate =strToUpdateUI;
What you can do next is create a method that "saves" your data.
Create a MySQL database and get its details. You can download wamp and install it on your local machine
Create a database and a table to hold your heart rate data
Your Android code might not be able to directly save data to a MySQL database, so you will need to write a web application (a simple mysqlhandler) written in any dynamic web app dev language of your choice which does this.
From your Android code, you make a web request and post your heart rate data to your MySQL web handler which inserts the data into MySQL.
There is a tutorial on how to build a PHP-based MySQL handler here and save data from Android.