Fix the server counterpart to be able to use JSON parsing

This commit is contained in:
TwistedUmbrella 2014-03-03 16:40:12 -05:00
parent 20291c57e8
commit b14440970b
3 changed files with 18 additions and 17 deletions

View File

@ -425,7 +425,7 @@ public class Debug extends Activity {
boolean hasIdentitiy = false;
String identity = mPrefs.getString(PREF_IDENTITY, "?");
if (!identity.equals("?")) {
mPairs.add(new BasicNameValuePair("sender", "reicast tester "
mPairs.add(new BasicNameValuePair("sender", "reicast tester #"
+ identity));
hasIdentitiy = true;
} else {
@ -535,7 +535,7 @@ public class Debug extends Activity {
if (!identity.equals("Err")) {
mPrefs.edit().putString(PREF_IDENTITY, identity).commit();
}
Log.d(APP_TAG, "reicast tester " + identity);
Log.d(APP_TAG, "reicast tester #" + identity);
}
}

View File

@ -37,7 +37,7 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
Log.d(TAG, "Sender: " + sender);
String message = extras.getString("message");
if (!message.equals("")) {
if (sender.contains("reicast tester ")) {
if (sender.contains("reicast tester #")) {
sendNotification(sender, message);
}
}
@ -50,13 +50,13 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
private void sendNotification(String sender, String message) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
final String number = sender.replace("reicast tester ", "");
final String number = sender.replace("reicast tester #", "");
long timestamp = System.currentTimeMillis();
int reference = (int) timestamp;
if (prefs.getBoolean("enable_messaging", true)) {
NotificationManager notificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
String title = "New reicast message!";
String title = "New reicast tester message!";
Notification notification;
Intent notificationIntent = new Intent(mContext, Debug.class);
// notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

View File

@ -65,6 +65,8 @@ import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
@ -86,23 +88,22 @@ public class RequestArchive extends AsyncTask<String, String, List<String[]>> {
@Override
protected List<String[]> doInBackground(String... urls) {
try {
List<String[]> message = new ArrayList<String[]>();
List<String[]> messages = new ArrayList<String[]>();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urls[0]);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = client.execute(post, responseHandler);
if (response.contains("[") && response.contains("]")) {
String[] jsonString = response.split(" , ");
for (String jsonText : jsonString) {
if (jsonText.contains("[\"")) {
jsonText = jsonText.replace("[\"", "");
}
if (jsonText.contains("\"]")) {
jsonText = jsonText.replace("\"]", "");
}
message.add(jsonText.split("\",\""));
if (response.contains("{") && response.contains("}")) {
JSONObject archive = new JSONObject(response);
JSONArray items = archive.getJSONArray("archive");
for (int i = 0; i < items.length(); i++) {
JSONObject log = items.getJSONObject(i);
String id = log.getString("identifier");
String msg = log.getString("message");
String date = log.getString("created_at");
messages.add(new String[] { id, msg, date });
}
return message;
return messages;
}
return null;