/** * Send a status bar notification. * * <p>The action triggered when the notification is selected is to start the {@link * CrashReportDialog} Activity. * * @param reportFileName Name of the report file to send. */ private void notifySendReport(String reportFileName) { // This notification can't be set to AUTO_CANCEL because after a crash, // clicking on it restarts the application and this triggers a check // for pending reports which issues the notification back. // Notification cancellation is done in the dialog activity displayed // on notification click. final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); final ReportsCrashes conf = ACRA.getConfig(); // Default notification icon is the warning symbol final int icon = conf.resNotifIcon(); final CharSequence tickerText = mContext.getText(conf.resNotifTickerText()); final long when = System.currentTimeMillis(); final Notification notification = new Notification(icon, tickerText, when); final CharSequence contentTitle = mContext.getText(conf.resNotifTitle()); final CharSequence contentText = mContext.getText(conf.resNotifText()); final Intent notificationIntent = new Intent(mContext, CrashReportDialog.class); Log.d(LOG_TAG, "Creating Notification for " + reportFileName); notificationIntent.putExtra(ACRAConstants.EXTRA_REPORT_FILE_NAME, reportFileName); final PendingIntent contentIntent = PendingIntent.getActivity( mContext, mNotificationCounter++, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(mContext, contentTitle, contentText, contentIntent); final Intent deleteIntent = new Intent(mContext, CrashReportDialog.class); deleteIntent.putExtra(ACRAConstants.EXTRA_FORCE_CANCEL, true); notification.deleteIntent = PendingIntent.getActivity(mContext, -1, deleteIntent, 0); // Send new notification notificationManager.notify(ACRAConstants.NOTIF_CRASH_ID, notification); }
/** * Sets relevant ReportSenders to the ErrorReporter, replacing any previously set ReportSender. */ public void setDefaultReportSenders() { ReportsCrashes conf = ACRA.getConfig(); Application mApplication = ACRA.getApplication(); removeAllReportSenders(); // Try to send by mail. If a mailTo address is provided, do not add // other senders. if (!"".equals(conf.mailTo())) { Log.w( LOG_TAG, mApplication.getPackageName() + " reports will be sent by email (if accepted by user)."); setReportSender(new EmailIntentSender(mApplication)); return; } final PackageManagerWrapper pm = new PackageManagerWrapper(mApplication); if (!pm.hasPermission(permission.INTERNET)) { // NB If the PackageManager has died then this will erroneously log // the error that the App doesn't have Internet (even though it // does). // I think that is a small price to pay to ensure that ACRA doesn't // crash if the PackageManager has died. Log.e( LOG_TAG, mApplication.getPackageName() + " should be granted permission " + permission.INTERNET + " if you want your crash reports to be sent. If you don't want to add this permission to your application you can also enable sending reports by email. If this is your will then provide your email address in @ReportsCrashes(mailTo=\"[email protected]\""); return; } // If formUri is set, instantiate a sender for a generic HTTP POST form // with default mapping. if (conf.formUri() != null && !"".equals(conf.formUri())) { setReportSender( new HttpSender(ACRA.getConfig().httpMethod(), ACRA.getConfig().reportType(), null)); } }