private void sendMessage(final Activity activity) { SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); prefs .edit() .putBoolean(Constants.PREF_KEY_MESSAGE_CENTER_SHOULD_SHOW_INTRO_DIALOG, false) .commit(); // Save the email. if (interaction.isAskForEmail()) { if (email != null && email.length() != 0) { PersonManager.storePersonEmail(activity, email.toString()); Person person = PersonManager.storePersonAndReturnDiff(activity); if (person != null) { Log.d("Person was updated."); Log.v(person.toString()); ApptentiveDatabase.getInstance(activity).addPayload(person); } else { Log.d("Person was not updated."); } } } // Send the message. final TextMessage textMessage = new TextMessage(); textMessage.setBody(message.toString()); textMessage.setRead(true); /* // TODO: Figure out how to add custom data here. textMessage.setCustomData(customData); customData = null; */ MessageManager.sendMessage(activity, textMessage); }
@Override public void doOnCreate(Activity activity, Bundle savedInstanceState) { // TODO: See if we can determine which app store the app was downloaded and go directly there. String errorMessage = activity.getString(R.string.apptentive_rating_error); boolean showingDialog = false; try { IRatingProvider ratingProvider = ApptentiveInternal.getRatingProvider(); errorMessage = ratingProvider.activityNotFoundMessage(activity); String appDisplayName = Configuration.load(activity).getAppDisplayName(); Map<String, String> ratingProviderArgs = ApptentiveInternal.getRatingProviderArgs(); Map<String, String> finalRatingProviderArgs; if (ratingProviderArgs != null) { finalRatingProviderArgs = new HashMap<String, String>(ratingProviderArgs); } else { finalRatingProviderArgs = new HashMap<String, String>(); } if (!finalRatingProviderArgs.containsKey("package")) { finalRatingProviderArgs.put("package", activity.getPackageName()); } if (!finalRatingProviderArgs.containsKey("name")) { finalRatingProviderArgs.put("name", appDisplayName); } ratingProvider.startRating(activity, finalRatingProviderArgs); } catch (ActivityNotFoundException e) { showingDialog = true; displayError(activity, errorMessage); } catch (InsufficientRatingArgumentsException e) { // TODO: Log a message to apptentive to let the developer know that their custom rating // provider puked? showingDialog = true; Log.e(e.getMessage()); displayError(activity, activity.getString(R.string.apptentive_rating_error)); } finally { if (!showingDialog) { Log.d("Finishing Activity."); activity.finish(); } } }
public void run() { try { synchronized (this) { if (appContext == null) { return; } PayloadStore db = getPayloadStore(appContext); while (true) { if (GlobalInfo.conversationToken == null || GlobalInfo.conversationToken.equals("")) { pause(NO_TOKEN_SLEEP); continue; } Payload payload; payload = db.getOldestUnsentPayload(); if (payload == null) { // There is no payload in the db. pause(EMPTY_QUEUE_SLEEP_TIME); continue; } Log.d("Got a payload to send: %s:%d", payload.getBaseType(), payload.getDatabaseId()); ApptentiveHttpResponse response = null; switch (payload.getBaseType()) { case message: response = ApptentiveClient.postMessage(appContext, (Message) payload); MessageManager.onSentMessage(appContext, (Message) payload, response); break; case event: response = ApptentiveClient.postEvent((Event) payload); break; case device: response = ApptentiveClient.putDevice((Device) payload); break; case sdk: response = ApptentiveClient.putSdk((Sdk) payload); break; case app_release: response = ApptentiveClient.putAppRelease((AppRelease) payload); break; case person: response = ApptentiveClient.putPerson((Person) payload); break; case survey: response = ApptentiveClient.postSurvey((SurveyPayload) payload); break; default: Log.e("Didn't send unknown Payload BaseType: " + payload.getBaseType()); db.deletePayload(payload); break; } // Each Payload type is handled by the appropriate handler, but if sent correctly, or // failed permanently to send, it should be removed from the queue. if (response != null) { if (response.isSuccessful()) { Log.d("Payload submission successful. Removing from send queue."); db.deletePayload(payload); } else if (response.isRejectedPermanently() || response.isBadpayload()) { Log.d("Payload rejected. Removing from send queue."); Log.v("Rejected json:", payload.toString()); db.deletePayload(payload); } else if (response.isRejectedTemporarily()) { Log.d("Unable to send JSON. Leaving in queue."); // Break the loop. Restart when network is reachable. break; } } } } } finally { running = false; } }