Search in sources :

Example 1 with NotificationClient

use of com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient in project aws-sdk-android by aws-amplify.

the class AnalyticsContextBuilder method build.

public PinpointContext build() {
    final SDKInfo mockSDKInfo = mock(SDKInfo.class);
    when(mockSDKInfo.getName()).thenReturn(sdkName);
    when(mockSDKInfo.getVersion()).thenReturn(sdkVersion);
    final MockUtil mockUtil = new MockUtil();
    if (mockUtil.isMock(mockSystem)) {
        when(mockSystem.getPreferences()).thenReturn(mockPreferences);
        when(mockSystem.getConnectivity()).thenReturn(mockConnectivity);
        final AndroidAppDetails mockAppDetails = new MockAppDetails();
        when(mockSystem.getAppDetails()).thenReturn(mockAppDetails);
        when(mockSystem.getDeviceDetails()).thenReturn(mockDeviceDetails);
    }
    final PinpointContext mockContext = mock(PinpointContext.class);
    when(mockContext.getSDKInfo()).thenReturn(mockSDKInfo);
    when(mockContext.getConfiguration()).thenReturn(mockConfig);
    when(mockContext.getUniqueId()).thenReturn(mockUniqueIdValue);
    when(mockContext.getAnalyticsServiceClient()).thenReturn(mockERS);
    when(mockContext.getPinpointServiceClient()).thenReturn(mockPinpointService);
    when(mockContext.getSystem()).thenReturn(mockSystem);
    // Notification client must be constructed after mock system is set
    mockNotificationClient = new NotificationClient(mockContext);
    when(mockContext.getNotificationClient()).thenReturn(mockNotificationClient);
    when(mockContext.getApplicationContext()).thenReturn(context);
    when(mockContext.getConfiguration()).thenReturn(mockConfig);
    when(mockContext.getNetworkType()).thenCallRealMethod();
    when(mockContext.getTargetingClient()).thenReturn(mockTargetingClient);
    when(mockContext.getPinpointConfiguration()).thenReturn(mockPinpointConfig);
    return mockContext;
}
Also used : MockAppDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AndroidAppDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails) MockUtil(org.mockito.internal.util.MockUtil) SDKInfo(com.amazonaws.mobileconnectors.pinpoint.internal.core.util.SDKInfo) NotificationClient(com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient)

Example 2 with NotificationClient

use of com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient in project zype-android by zype.

the class PushListenerService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Logger.d("onMessageReceived(): data=" + remoteMessage.getData());
    if (!BuildConfig.AWS_PINPOINT) {
        return;
    }
    final NotificationClient notificationClient = ZypeApp.getPinpointManager(this).getNotificationClient();
    final NotificationDetails notificationDetails = NotificationDetails.builder().from(remoteMessage.getFrom()).mapData(remoteMessage.getData()).intentAction(NotificationClient.FCM_INTENT_ACTION).build();
    NotificationClient.CampaignPushResult pushResult = notificationClient.handleCampaignPush(notificationDetails);
    if (!NotificationClient.CampaignPushResult.NOT_HANDLED.equals(pushResult)) {
        /**
         *             The push message was due to a Pinpoint campaign.
         *             If the app was in the background, a local notification was added
         *             in the notification center. If the app was in the foreground, an
         *             event was recorded indicating the app was in the foreground,
         *             for the demo, we will broadcast the notification to let the main
         *             activity display it in a dialog.
         */
        if (NotificationClient.CampaignPushResult.APP_IN_FOREGROUND.equals(pushResult)) {
            /* Create a message that will display the raw data of the campaign push in a dialog. */
            final HashMap<String, String> dataMap = new HashMap<>(remoteMessage.getData());
            broadcast(remoteMessage.getFrom(), dataMap);
        }
        return;
    }
}
Also used : NotificationDetails(com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationDetails) HashMap(java.util.HashMap) NotificationClient(com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient)

Aggregations

NotificationClient (com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient)2 PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)1 AndroidAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails)1 MockAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails)1 SDKInfo (com.amazonaws.mobileconnectors.pinpoint.internal.core.util.SDKInfo)1 NotificationDetails (com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationDetails)1 HashMap (java.util.HashMap)1 MockUtil (org.mockito.internal.util.MockUtil)1