urbanairship-core/src/main/java/com/urbanairship/analytics/data/EventApiClient.java
EventResponse sendEvents(UAirship airship, @NonNull Collection<String> events) {
        if (events.size() == 0) {
            Logger.verbose("EventApiClient - No analytics events to send.");
            return null;
        }

        List<JsonValue> eventJSON = new ArrayList<>();

        for (String eventPayload : events) {
            try {
                eventJSON.add(JsonValue.parseString(eventPayload));
            } catch (JsonException e) {
                Logger.error("EventApiClient - Invalid eventPayload.", e);
            }
        }

        String payload = new JsonList(eventJSON).toString();

        String url = airship.getAirshipConfigOptions().analyticsServer + "warp9/";
        URL analyticsServerUrl = null;
        try {
            analyticsServerUrl = new URL(url);
        } catch (MalformedURLException e) {
            Logger.error("EventApiClient - Invalid analyticsServer: " + url, e);
        }

        String deviceFamily;
        if (airship.getPlatformType() == UAirship.AMAZON_PLATFORM) {
            deviceFamily = "amazon";
        } else {
            deviceFamily = "android";
        }

        double sentAt = System.currentTimeMillis() / 1000.0;

        // CE-2745: Calling BluetoothAdapter.getDefaultAdapter() results in a RuntimeException on
        // devices running Ice Cream Sandwich http://stackoverflow.com/a/15036421
        String bluetoothEnabled = "false";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            bluetoothEnabled = Boolean.toString(isBluetoothEnabled());
        }

        Request request = requestFactory.createRequest("POST", analyticsServerUrl)
                                        .setRequestBody(payload, "application/json")
                                        .setCompressRequestBody(true)
                                        .setHeader("X-UA-Device-Family", deviceFamily)
                                        .setHeader("X-UA-Sent-At", String.format(Locale.US, "%.3f", sentAt))
                                        .setHeader("X-UA-Package-Name", getPackageName())
                                        .setHeader("X-UA-Package-Version", getPackageVersion())
                                        .setHeader("X-UA-App-Key", airship.getAirshipConfigOptions().getAppKey())
                                        .setHeader("X-UA-In-Production", Boolean.toString(airship.getAirshipConfigOptions().inProduction))
                                        .setHeader("X-UA-Device-Model", Build.MODEL)
                                        .setHeader("X-UA-Android-Version-Code", String.valueOf(Build.VERSION.SDK_INT))
                                        .setHeader("X-UA-Lib-Version", UAirship.getVersion())
                                        .setHeader("X-UA-Timezone", TimeZone.getDefault().getID())
                                        .setHeader("X-UA-Channel-Opted-In",
                                                Boolean.toString(airship.getPushManager().isOptIn()))
                                        .setHeader("X-UA-Channel-Background-Enabled",
                                                Boolean.toString(airship.getPushManager().isPushEnabled() &&
                                                        airship.getPushManager().isPushAvailable()))
                                        .setHeader("X-UA-Location-Permission", getLocationPermission())
                                        .setHeader("X-UA-Location-Service-Enabled",
                                                Boolean.toString(airship.getLocationManager().isLocationUpdatesEnabled()))
                                        .setHeader("X-UA-Bluetooth-Status", bluetoothEnabled)
                                        .setHeader("X-UA-User-ID", airship.getInbox().getUser().getId());


        Locale locale = Locale.getDefault();
        if (!UAStringUtil.isEmpty(locale.getLanguage())) {
            request.setHeader("X-UA-Locale-Language", locale.getLanguage());

            if (!UAStringUtil.isEmpty(locale.getCountry())) {
                request.setHeader("X-UA-Locale-Country", locale.getCountry());
            }

            if (!UAStringUtil.isEmpty(locale.getVariant())) {
                request.setHeader("X-UA-Locale-Variant", locale.getVariant());
            }
        }

        String channelID = airship.getPushManager().getChannelId();
        if (!UAStringUtil.isEmpty(channelID)) {
            request.setHeader("X-UA-Channel-ID", channelID);
            // Send the Channel ID instead of the Registration ID as the Push Address for
            // analytics because the GCM Registration ID for Android and the ADM Registration ID
            // for Amazon can be too large (both may be greater than 4K).
            request.setHeader("X-UA-Push-Address", channelID);
        }

        Logger.debug("EventApiClient - Sending analytics events. Request:  " + request + " Events: " + events);

        Response response = request.execute();


        Logger.debug("EventApiClient - Analytics event response: " + response);


        return response == null ? null : new EventResponse(response);
    }
/**
     * Sends a collection of events.
     *
     * @param airship The {@link UAirship} instance.
     * @param events Specified events
     * @return eventResponse or null if an error occurred
     */
Sends a collection of events.
@param airship The  UAirship instance.
@param events Specified events
@return eventResponse or null if an error occurred
Sends a collection of events . @param airship The UAirship instance . @param events Specified events @return eventResponse or null if an error occurred
EventResponse sendEvents(UAirship airship, @NonNull Collection<String> events) {
        if (events.size() == 0) {
            Logger.verbose("EventApiClient - No analytics events to send.");
            return null;
        }
        List<JsonValue> eventJSON = new ArrayList<>();
        for (String eventPayload : events) {
            try {
                eventJSON.add(JsonValue.parseString(eventPayload));
            } catch (JsonException e) {
                Logger.error("EventApiClient - Invalid eventPayload.", e);
            }
        }
        String payload = new JsonList(eventJSON).toString();
        String url = airship.getAirshipConfigOptions().analyticsServer + "warp9/";
        URL analyticsServerUrl = null;
        try {
            analyticsServerUrl = new URL(url);
        } catch (MalformedURLException e) {
            Logger.error("EventApiClient - Invalid analyticsServer: " + url, e);
        }
        String deviceFamily;
        if (airship.getPlatformType() == UAirship.AMAZON_PLATFORM) {
            deviceFamily = "amazon";
        } else {
            deviceFamily = "android";
        }
        double sentAt = System.currentTimeMillis() / 1000.0;
        String bluetoothEnabled = "false";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            bluetoothEnabled = Boolean.toString(isBluetoothEnabled());
        }
        Request request = requestFactory.createRequest("POST", analyticsServerUrl)
                                        .setRequestBody(payload, "application/json")
                                        .setCompressRequestBody(true)
                                        .setHeader("X-UA-Device-Family", deviceFamily)
                                        .setHeader("X-UA-Sent-At", String.format(Locale.US, "%.3f", sentAt))
                                        .setHeader("X-UA-Package-Name", getPackageName())
                                        .setHeader("X-UA-Package-Version", getPackageVersion())
                                        .setHeader("X-UA-App-Key", airship.getAirshipConfigOptions().getAppKey())
                                        .setHeader("X-UA-In-Production", Boolean.toString(airship.getAirshipConfigOptions().inProduction))
                                        .setHeader("X-UA-Device-Model", Build.MODEL)
                                        .setHeader("X-UA-Android-Version-Code", String.valueOf(Build.VERSION.SDK_INT))
                                        .setHeader("X-UA-Lib-Version", UAirship.getVersion())
                                        .setHeader("X-UA-Timezone", TimeZone.getDefault().getID())
                                        .setHeader("X-UA-Channel-Opted-In",
                                                Boolean.toString(airship.getPushManager().isOptIn()))
                                        .setHeader("X-UA-Channel-Background-Enabled",
                                                Boolean.toString(airship.getPushManager().isPushEnabled() &&
                                                        airship.getPushManager().isPushAvailable()))
                                        .setHeader("X-UA-Location-Permission", getLocationPermission())
                                        .setHeader("X-UA-Location-Service-Enabled",
                                                Boolean.toString(airship.getLocationManager().isLocationUpdatesEnabled()))
                                        .setHeader("X-UA-Bluetooth-Status", bluetoothEnabled)
                                        .setHeader("X-UA-User-ID", airship.getInbox().getUser().getId());
        Locale locale = Locale.getDefault();
        if (!UAStringUtil.isEmpty(locale.getLanguage())) {
            request.setHeader("X-UA-Locale-Language", locale.getLanguage());
            if (!UAStringUtil.isEmpty(locale.getCountry())) {
                request.setHeader("X-UA-Locale-Country", locale.getCountry());
            }
            if (!UAStringUtil.isEmpty(locale.getVariant())) {
                request.setHeader("X-UA-Locale-Variant", locale.getVariant());
            }
        }
        String channelID = airship.getPushManager().getChannelId();
        if (!UAStringUtil.isEmpty(channelID)) {
            request.setHeader("X-UA-Channel-ID", channelID);
            request.setHeader("X-UA-Push-Address", channelID);
        }
        Logger.debug("EventApiClient - Sending analytics events. Request:  " + request + " Events: " + events);
        Response response = request.execute();
        Logger.debug("EventApiClient - Analytics event response: " + response);
        return response == null ? null : new EventResponse(response);
    }
EventResponse sendEvents ( UAirship airship , @ NonNull Collection < String > events ) { if ( events . size ( ) == 0 ) { Logger . verbose ( "EventApiClient - No analytics events to send." ) ; return null ; } List < JsonValue > eventJSON = new ArrayList < > ( ) ; for ( String eventPayload : events ) { try { eventJSON . add ( JsonValue . parseString ( eventPayload ) ) ; } catch ( JsonException e ) { Logger . error ( "EventApiClient - Invalid eventPayload." , e ) ; } } String payload = new JsonList ( eventJSON ) . toString ( ) ; String url = airship . getAirshipConfigOptions ( ) . analyticsServer + "warp9/" ; URL analyticsServerUrl = null ; try { analyticsServerUrl = new URL ( url ) ; } catch ( MalformedURLException e ) { Logger . error ( "EventApiClient - Invalid analyticsServer: " + url , e ) ; } String deviceFamily ; if ( airship . getPlatformType ( ) == UAirship . AMAZON_PLATFORM ) { deviceFamily = "amazon" ; } else { deviceFamily = "android" ; } double sentAt = System . currentTimeMillis ( ) / 1000.0 ; String bluetoothEnabled = "false" ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN ) { bluetoothEnabled = Boolean . toString ( isBluetoothEnabled ( ) ) ; } Request request = requestFactory . createRequest ( "POST" , analyticsServerUrl ) . setRequestBody ( payload , "application/json" ) . setCompressRequestBody ( true ) . setHeader ( "X-UA-Device-Family" , deviceFamily ) . setHeader ( "X-UA-Sent-At" , String . format ( Locale . US , "%.3f" , sentAt ) ) . setHeader ( "X-UA-Package-Name" , getPackageName ( ) ) . setHeader ( "X-UA-Package-Version" , getPackageVersion ( ) ) . setHeader ( "X-UA-App-Key" , airship . getAirshipConfigOptions ( ) . getAppKey ( ) ) . setHeader ( "X-UA-In-Production" , Boolean . toString ( airship . getAirshipConfigOptions ( ) . inProduction ) ) . setHeader ( "X-UA-Device-Model" , Build . MODEL ) . setHeader ( "X-UA-Android-Version-Code" , String . valueOf ( Build . VERSION . SDK_INT ) ) . setHeader ( "X-UA-Lib-Version" , UAirship . getVersion ( ) ) . setHeader ( "X-UA-Timezone" , TimeZone . getDefault ( ) . getID ( ) ) . setHeader ( "X-UA-Channel-Opted-In" , Boolean . toString ( airship . getPushManager ( ) . isOptIn ( ) ) ) . setHeader ( "X-UA-Channel-Background-Enabled" , Boolean . toString ( airship . getPushManager ( ) . isPushEnabled ( ) && airship . getPushManager ( ) . isPushAvailable ( ) ) ) . setHeader ( "X-UA-Location-Permission" , getLocationPermission ( ) ) . setHeader ( "X-UA-Location-Service-Enabled" , Boolean . toString ( airship . getLocationManager ( ) . isLocationUpdatesEnabled ( ) ) ) . setHeader ( "X-UA-Bluetooth-Status" , bluetoothEnabled ) . setHeader ( "X-UA-User-ID" , airship . getInbox ( ) . getUser ( ) . getId ( ) ) ; Locale locale = Locale . getDefault ( ) ; if ( ! UAStringUtil . isEmpty ( locale . getLanguage ( ) ) ) { request . setHeader ( "X-UA-Locale-Language" , locale . getLanguage ( ) ) ; if ( ! UAStringUtil . isEmpty ( locale . getCountry ( ) ) ) { request . setHeader ( "X-UA-Locale-Country" , locale . getCountry ( ) ) ; } if ( ! UAStringUtil . isEmpty ( locale . getVariant ( ) ) ) { request . setHeader ( "X-UA-Locale-Variant" , locale . getVariant ( ) ) ; } } String channelID = airship . getPushManager ( ) . getChannelId ( ) ; if ( ! UAStringUtil . isEmpty ( channelID ) ) { request . setHeader ( "X-UA-Channel-ID" , channelID ) ; request . setHeader ( "X-UA-Push-Address" , channelID ) ; } Logger . debug ( "EventApiClient - Sending analytics events. Request:  " + request + " Events: " + events ) ; Response response = request . execute ( ) ; Logger . debug ( "EventApiClient - Analytics event response: " + response ) ; return response == null ? null : new EventResponse ( response ) ; }
Sends a collection of events.
Sends a collection of events .
// CE-2745: Calling BluetoothAdapter.getDefaultAdapter() results in a RuntimeException on // devices running Ice Cream Sandwich http://stackoverflow.com/a/15036421 // Send the Channel ID instead of the Registration ID as the Push Address for // analytics because the GCM Registration ID for Android and the ADM Registration ID // for Amazon can be too large (both may be greater than 4K).