Load token

This commit is contained in:
Ruben van de Ven 2018-10-30 13:14:57 +01:00
parent 0a47e53ffb
commit 43c11574a8
4 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@
/build /build
/captures /captures
.externalNativeBuild .externalNativeBuild
token.json

View file

@ -0,0 +1 @@
{"token":"abcdefghijklmnop"}

View file

@ -15,6 +15,11 @@ import com.rubenvandeven.heartbeatstreamer.heartrate.Activity_AsyncScanHeartRate
import com.rubenvandeven.heartbeatstreamer.heartrate.Activity_SearchUiHeartRateSampler; import com.rubenvandeven.heartbeatstreamer.heartrate.Activity_SearchUiHeartRateSampler;
import com.rubenvandeven.heartbeatstreamer.heartrate.HeartRateService; import com.rubenvandeven.heartbeatstreamer.heartrate.HeartRateService;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -127,4 +132,33 @@ public class MainActivity extends AppCompatActivity {
} }
}; };
/**
* Get the token for use with the syncing.
* @return
*/
public String getToken() {
String json = null;
String token = null;
try {
InputStream is = getAssets().open("token.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
try {
JSONObject jsonObject = new JSONObject(json);
token = jsonObject.getString("token'");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return token;
}
} }

View file

@ -53,7 +53,6 @@ public class HeartRateService extends Service {
requestAccessToPcc(); requestAccessToPcc();
} }
/** /**
* Start main thread, request location updates, start synchronization. * Start main thread, request location updates, start synchronization.
* *