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;
}
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;
}
}
Aggregations