diff --git a/ExceptionHandlerLib/res/values/strings.xml b/ExceptionHandlerLib/res/values/strings.xml index b1d79f3..40d0133 100644 --- a/ExceptionHandlerLib/res/values/strings.xml +++ b/ExceptionHandlerLib/res/values/strings.xml @@ -8,5 +8,6 @@ Optional: Describe what happened Version No Reports + Sending Exception Report \ No newline at end of file diff --git a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionHandler.java b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionHandler.java index 9bef466..2e4a57a 100644 --- a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionHandler.java +++ b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionHandler.java @@ -143,7 +143,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable { InputStream inputStream = assetManager.open("exceptionhandler.properties"); Properties properties = new Properties(); properties.load(inputStream); - this.mURL = properties.getProperty("server") + properties.getProperty("file"); + this.mURL = properties.getProperty("server"); this.mEmail = properties.getProperty("email"); this.mAppName = properties.getProperty("app"); this.mTracker = properties.getProperty("tracker"); diff --git a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionReportActivity.java b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionReportActivity.java index 51d8a6d..8c818d6 100644 --- a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionReportActivity.java +++ b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ExceptionReportActivity.java @@ -6,14 +6,9 @@ */ package com.TwentyCodes.android.exception; -import java.io.IOException; - -import org.apache.http.client.ClientProtocolException; - import android.app.Activity; -import android.app.ProgressDialog; +import android.content.Intent; import android.os.Bundle; -import android.os.Looper; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; @@ -61,21 +56,7 @@ public class ExceptionReportActivity extends Activity implements OnClickListener EditText description = (EditText) findViewById(R.id.description); this.mReport.setDescription(description.getText().toString()); v.setEnabled(false); - final ProgressDialog progress = ProgressDialog.show(this, "", getString(R.string.sending), true, true); - new Thread( new Runnable(){ - @Override - public void run(){ - Looper.prepare(); - try { - Log.d(TAG, ExceptionReportActivity.this.mReport.file()); - } catch (ClientProtocolException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - progress.dismiss(); - ExceptionReportActivity.this.finish(); - } - }).start(); + this.startService(new Intent(this, ReportPostingService.class).putExtra("report", this.mReport)); + this.finish(); } } \ No newline at end of file diff --git a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/Report.java b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/Report.java index 2afaef2..691ca28 100644 --- a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/Report.java +++ b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/Report.java @@ -27,6 +27,7 @@ import org.json.JSONObject; import android.os.Parcel; import android.os.Parcelable; +import android.util.Log; /** * This class will be used to generate a report, and insert it into our exception report database @@ -34,6 +35,7 @@ import android.os.Parcelable; */ public class Report implements Parcelable{ + private static final String TAG = "Report"; private final String mUrl; private ArrayList mReport; @@ -62,8 +64,9 @@ public class Report implements Parcelable{ * Creates a new Report * @author ricky barrette */ - public Report(String mysqlUrl) { - this.mUrl = mysqlUrl; + public Report(String url) { + Log.d(TAG, url); + this.mUrl = url; } @Override diff --git a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java new file mode 100644 index 0000000..5a53dca --- /dev/null +++ b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java @@ -0,0 +1,130 @@ +/** + * ReportPostingService.java + * @date Feb 29, 2012 + * @author ricky barrette + * @author Twenty Codes, LLC + */ +package com.TwentyCodes.android.exception; + +import java.io.IOException; + +import org.apache.http.client.ClientProtocolException; + +import android.app.Notification; +import android.app.Notification.Builder; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * This service will allow the exception handler to post reports in the backgound, + * allowing the user to do what ever they want + * @author ricky barrette + */ +public class ReportPostingService extends Service { + + public static final int NOTIFICATION_ID = 1973646478; + private NotificationManager mNotificationManager; + private static final String TAG = "ReportPostingService"; + private int mStartId; + private Report mReport; + + /** + * Extracts the report object from the intent + * @param intent + * @author ricky barrette + */ + private void getReport(Intent intent) { + mReport = (Report) intent.getParcelableExtra("report"); + } + /** + * (non-Javadoc) + * @see android.app.Service#onBind(android.content.Intent) + */ + @Override + public IBinder onBind(Intent intent) { + // Unused + return null; + } + + /** + * Called when the service is being created + * Here we want to display a notifcation, + * to inform the user what we are doing. + * (non-Javadoc) + * @see android.app.Service#onCreate() + */ + @Override + public void onCreate() { + Context context = this.getApplicationContext(); + mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + Builder builder = new Notification.Builder(context) + .setContentTitle(getText(R.string.sending)) + .setContentText(getText(R.string.sending_report)) + .setTicker(getText(R.string.sending)) + .setOngoing(true) + .setSmallIcon(android.R.drawable.stat_sys_upload) + .setWhen(System.currentTimeMillis()); + mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); + super.onCreate(); + } + + /** + * Called when the service is being destroyed + * Here we want to dismiss the notifications + * (non-Javadoc) + * @see android.app.Service#onDestroy() + */ + @Override + public void onDestroy() { + mNotificationManager.cancel(NOTIFICATION_ID); + super.onDestroy(); + } + + /** + * (non-Javadoc) + * @see android.app.Service#onStart(android.content.Intent, int) + */ + @Override + public void onStart(Intent intent, int startId) { + mStartId = startId; + getReport(intent); + postReport(); + super.onStart(intent, startId); + } + + /** + * (non-Javadoc) + * @see android.app.Service#onStartCommand(android.content.Intent, int, int) + */ + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + mStartId = startId; + getReport(intent); + postReport(); + return super.onStartCommand(intent, Service.START_STICKY, startId); + } + + /** + * Posts a copy of the report to the report handing server + * @author ricky barrette + */ + private void postReport(){ + new Thread(new Runnable() { + @Override + public void run(){ + try { + Log.d(TAG, mReport.file()); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + ReportPostingService.this.stopSelf(mStartId); + } + }).start(); + } +}