Try again notification
added a notification for users to try to send the report again closes #32 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -2,12 +2,14 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="crash">Application Fault</string>
|
<string name="crash">Application Fault</string>
|
||||||
<string name="sorry">I\'m sorry, but we found a problem. Please click here.</string>
|
<string name="sorry">We found a problem. Please click here.</string>
|
||||||
<string name="sending">Sending…</string>
|
<string name="sending">Sending…</string>
|
||||||
<string name="send">Send</string>
|
<string name="send">Send</string>
|
||||||
<string name="description">Optional: Describe what happened</string>
|
<string name="description">Optional: Describe what happened</string>
|
||||||
<string name="version">Version</string>
|
<string name="version">Version</string>
|
||||||
<string name="no_reports">No Reports</string>
|
<string name="no_reports">No Reports</string>
|
||||||
<string name="sending_report">Sending Exception Report</string>
|
<string name="sending_report">Sending Exception Report</string>
|
||||||
|
<string name="reporting_error">Problem sending the report</string>
|
||||||
|
<string name="reporting_error_msg">Please click here to try again</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -33,7 +33,52 @@ public class ReportPostingService extends Service {
|
|||||||
private int mStartId;
|
private int mStartId;
|
||||||
private Report mReport;
|
private Report mReport;
|
||||||
private boolean isStarted;
|
private boolean isStarted;
|
||||||
|
private Intent mIntent;
|
||||||
|
private boolean hasErrored = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires of a notification based upon api level
|
||||||
|
* @param title
|
||||||
|
* @param contentText
|
||||||
|
* @param ticker
|
||||||
|
* @param icon
|
||||||
|
* @param intent
|
||||||
|
* @param isOngoing
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void fireNotification(String title, String contentText, String ticker, int icon, Intent intent, boolean isOngoing) {
|
||||||
|
PendingIntent pendingIntent = null;
|
||||||
|
if(intent != null)
|
||||||
|
pendingIntent = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0);
|
||||||
|
/*
|
||||||
|
* Use the appropriate notificafation methods
|
||||||
|
*/
|
||||||
|
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){
|
||||||
|
Builder builder = new Notification.Builder(this.getApplicationContext())
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(contentText)
|
||||||
|
.setTicker(ticker)
|
||||||
|
.setSmallIcon(icon)
|
||||||
|
.setWhen(System.currentTimeMillis());
|
||||||
|
if(isOngoing)
|
||||||
|
builder.setOngoing(true);
|
||||||
|
else
|
||||||
|
builder.setAutoCancel(true);
|
||||||
|
if (intent != null)
|
||||||
|
builder.setContentIntent(pendingIntent);
|
||||||
|
mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
|
||||||
|
} else {
|
||||||
|
Notification notification = new Notification(icon, title , System.currentTimeMillis());
|
||||||
|
if(isOngoing)
|
||||||
|
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||||
|
else
|
||||||
|
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||||
|
notification.setLatestEventInfo(this.getApplicationContext(), title, contentText, pendingIntent);
|
||||||
|
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the report object from the intent
|
* Extracts the report object from the intent
|
||||||
* @param intent
|
* @param intent
|
||||||
@@ -42,6 +87,34 @@ public class ReportPostingService extends Service {
|
|||||||
private void getReport(Intent intent) {
|
private void getReport(Intent intent) {
|
||||||
mReport = (Report) intent.getParcelableExtra("report");
|
mReport = (Report) intent.getParcelableExtra("report");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifiys the user that we are sending a report
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private void notifyError() {
|
||||||
|
fireNotification(getString(R.string.reporting_error),
|
||||||
|
getString(R.string.reporting_error_msg),
|
||||||
|
getString(R.string.reporting_error_msg),
|
||||||
|
android.R.drawable.stat_notify_error,
|
||||||
|
new Intent(this.getApplicationContext(), ReportPostingService.class).putExtras(mIntent),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifiys the user that we are sending a report
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private void notifySending() {
|
||||||
|
fireNotification(getString(R.string.sending),
|
||||||
|
getString(R.string.sending_report),
|
||||||
|
getString(R.string.sending),
|
||||||
|
android.R.drawable.stat_sys_upload,
|
||||||
|
null,
|
||||||
|
true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.app.Service#onBind(android.content.Intent)
|
* @see android.app.Service#onBind(android.content.Intent)
|
||||||
@@ -51,7 +124,7 @@ public class ReportPostingService extends Service {
|
|||||||
// Unused
|
// Unused
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the service is being created
|
* Called when the service is being created
|
||||||
* Here we want to display a notifcation,
|
* Here we want to display a notifcation,
|
||||||
@@ -59,33 +132,14 @@ public class ReportPostingService extends Service {
|
|||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.app.Service#onCreate()
|
* @see android.app.Service#onCreate()
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Context context = this.getApplicationContext();
|
Context context = this.getApplicationContext();
|
||||||
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
/*
|
notifySending();
|
||||||
* Use the appropriate notificafation methods
|
|
||||||
*/
|
|
||||||
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){
|
|
||||||
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());
|
|
||||||
} else {
|
|
||||||
Notification notification = new Notification(android.R.drawable.stat_sys_upload, getText(R.string.sending) , System.currentTimeMillis());
|
|
||||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
|
||||||
notification.setLatestEventInfo(context, getText(R.string.sending_report), getText(R.string.sending), PendingIntent.getActivity(context, 0, null, 0));
|
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
|
||||||
}
|
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the service is being destroyed
|
* Called when the service is being destroyed
|
||||||
* Here we want to dismiss the notifications
|
* Here we want to dismiss the notifications
|
||||||
@@ -95,6 +149,8 @@ public class ReportPostingService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
mNotificationManager.cancel(NOTIFICATION_ID);
|
mNotificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
if (hasErrored)
|
||||||
|
notifyError();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +164,7 @@ public class ReportPostingService extends Service {
|
|||||||
mStartId = startId;
|
mStartId = startId;
|
||||||
getReport(intent);
|
getReport(intent);
|
||||||
postReport();
|
postReport();
|
||||||
|
mIntent = intent;
|
||||||
super.onStart(intent, startId);
|
super.onStart(intent, startId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +177,7 @@ public class ReportPostingService extends Service {
|
|||||||
mStartId = startId;
|
mStartId = startId;
|
||||||
getReport(intent);
|
getReport(intent);
|
||||||
postReport();
|
postReport();
|
||||||
|
mIntent = intent;
|
||||||
return super.onStartCommand(intent, Service.START_STICKY, startId);
|
return super.onStartCommand(intent, Service.START_STICKY, startId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,20 +188,17 @@ public class ReportPostingService extends Service {
|
|||||||
private void postReport(){
|
private void postReport(){
|
||||||
if(!isStarted){
|
if(!isStarted){
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
new Thread(new Runnable() {
|
try {
|
||||||
@Override
|
Log.d(TAG, mReport.file());
|
||||||
public void run(){
|
} catch (ClientProtocolException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
Log.d(TAG, mReport.file());
|
hasErrored = true;
|
||||||
} catch (ClientProtocolException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
hasErrored = true;
|
||||||
e.printStackTrace();
|
} finally {
|
||||||
} finally {
|
ReportPostingService.this.stopSelf(mStartId);
|
||||||
ReportPostingService.this.stopSelf(mStartId);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user