public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // OPTIONAL: To specify a different user email than what the device was setup with.
    // Apptentive.setInitialUserEmail(this, "*****@*****.**");

    // OPTIONAL: To send extra about the device to the server.
    // Apptentive.addCustomDeviceData(this, "custom_device_key", "custom_device_value");
    // Apptentive.addCustomPersonData(this, "custom_person_key", "custom_person_value");

    // OPTIONAL: Specify a different rating provider if your app is not served from Google Play.
    // Apptentive.setRatingProvider(new AmazonAppstoreRatingProvider());

    // Impersonate an app for ratings.
    // Apptentive.putRatingProviderArg("package", "your.package.name");

    // If you would like to be notified when there are unread messages available, set a listener
    // like this.
    Apptentive.setUnreadMessagesListener(
        new UnreadMessagesListener() {
          public void onUnreadMessageCountChanged(final int unreadMessages) {
            Log.e(LOG_TAG, "There are " + unreadMessages + " unread messages.");
            runOnUiThread(
                new Runnable() {
                  public void run() {
                    Button messageCenterButton = (Button) findViewById(R.id.button_message_center);
                    if (messageCenterButton != null) {
                      messageCenterButton.setText("Message Center, unread = " + unreadMessages);
                    }
                    if (lastUnreadMessageCount != unreadMessages) {
                      Toast.makeText(
                              MainActivity.this,
                              "You have " + unreadMessages + " unread messages.",
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                    lastUnreadMessageCount = unreadMessages;
                  }
                });
          }
        });

    // Ad a listener to notify you when a survey is completed.
    Apptentive.setOnSurveyFinishedListener(
        new OnSurveyFinishedListener() {
          @Override
          public void onSurveyFinished(boolean completed) {
            Toast.makeText(
                    MainActivity.this,
                    completed ? "Survey was completed." : "Survey was skipped.",
                    Toast.LENGTH_SHORT)
                .show();
          }
        });
  }
Example #2
0
  @Override
  protected void onStart() {
    super.onStart();

    try {
      switch (activeContentType) {
        case ABOUT:
          AboutModule.getInstance().doShow(this);
          break;
        case MESSAGE_CENTER:
          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
          ApptentiveMessageCenter.doShow(this);
          break;
        case INTERACTION:
          String interactionString =
              getIntent().getExtras().getCharSequence(Interaction.KEY_NAME).toString();
          Interaction interaction = Interaction.Factory.parseInteraction(interactionString);
          InteractionView view = null;
          switch (interaction.getType()) {
            case UpgradeMessage:
              view = new UpgradeMessageInteractionView((UpgradeMessageInteraction) interaction);
              break;
            case EnjoymentDialog:
              view = new EnjoymentDialogInteractionView((EnjoymentDialogInteraction) interaction);
              break;
            case RatingDialog:
              view = new RatingDialogInteractionView((RatingDialogInteraction) interaction);
              break;
            case AppStoreRating:
              view = new AppStoreRatingInteractionView((AppStoreRatingInteraction) interaction);
              break;
            case FeedbackDialog:
              view = new FeedbackDialogInteractionView((FeedbackDialogInteraction) interaction);
              break;
            case Survey:
              view = new SurveyInteractionView((SurveyInteraction) interaction);
              break;
            case MessageCenter:
              // For now, we use the old method.
              getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
              finish();
              Apptentive.showMessageCenter(this);
              return;
            default:
              break;
          }
          activityContent = view;
          if (view == null) {
            finish();
          } else {
            view.show(this);
          }
          break;
        default:
          Log.w("No Activity specified. Finishing...");
          finish();
          break;
      }
    } catch (Exception e) {
      Log.e("Error starting ViewActivity.", e);
      MetricModule.sendError(this, e, null, null);
    }
  }
 public void showMessageCenter(@SuppressWarnings("unused") View view) {
   Apptentive.showMessageCenter(this);
 }