Created
October 20, 2014 20:43
-
-
Save marinat/450eae44d018fd3c9356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void sendInfoToServer(int serverId) { | |
sendCount = 0; | |
final File logFile = new File(Environment.getExternalStorageDirectory(), "/temp/statist/logs.txt"); | |
if (!logFile.exists()) | |
return; | |
final JSONArray jsonToSendArray = new JSONArray(); | |
try { | |
FileInputStream inputStream = new FileInputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/statist/logs.txt"); | |
if (inputStream != null) { | |
InputStreamReader inputStreamReader = new InputStreamReader(inputStream); | |
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); | |
String receiveString = ""; | |
while ((receiveString = bufferedReader.readLine()) != null) { | |
//Log.d(TAG, "rcvSTRING = " + receiveString); | |
String[] parts = receiveString.split(";"); | |
JSONObject sessionObj = new JSONObject(); | |
try { | |
sessionObj.put("packageName", parts[0]); | |
sessionObj.put("duration", parts[1]); | |
sessionObj.put("timeStamp", parts[2]); | |
sessionObj.put("installed", parts.length > 3); | |
sessionObj.put("profileId", serverId); | |
} catch (JSONException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
jsonToSendArray.put(sessionObj); | |
//Log.d(TAG, "jArray = " + jsonToSendArray.toString()); | |
} | |
inputStream.close(); | |
} | |
} catch (FileNotFoundException e) { | |
Log.e("login activity", "File not found: " + e.toString()); | |
} catch (IOException e) { | |
Log.e("login activity", "Can not read file: " + e.toString()); | |
} | |
if (jsonToSendArray.length()<1) | |
return; | |
Thread sendThread = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
String url = "http://chartlight.org/stat/session"; | |
HttpResponse re; | |
//String temp = null; | |
try { | |
re = HTTPPoster.doPost(url, jsonToSendArray); | |
EntityUtils.toString(re.getEntity()); | |
//Log.d(TAG, "resp from STAT = " + temp); | |
if (logFile.exists()) | |
logFile.delete(); | |
} catch (ClientProtocolException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
sendThread.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment