Ejemplo n.º 1
0
  /**
   * 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);
  }