Created ReportPostingService

Updated the exception report activity to use the new
ReportPostingService to file new reports

Removed file option from the exception handler

Change-Id: Ie15b416f7764753f7f2a2e50159acd12efc2fa51
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-02-29 12:49:30 -05:00
parent 4e7c01d96e
commit 4258c29d01
5 changed files with 140 additions and 25 deletions

View File

@@ -8,5 +8,6 @@
<string name="description">Optional: Describe what happened</string>
<string name="version">Version</string>
<string name="no_reports">No Reports</string>
<string name="sending_report">Sending Exception Report</string>
</resources>

View File

@@ -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");

View File

@@ -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();
}
}

View File

@@ -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<ReportItem> 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

View File

@@ -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();
}
}