This is the exact code that I am using for configure sfmcsdk. In the sdkstate, the device token is fetched as null when senderID is not set. I have tried by setting SenderID as FCM senderID.
if (BuildConfig.DEBUG) {
// LogManager.setVerboseLoggingEnabled(true);
MarketingCloudSdk.setLogLevel(MCLogListener.VERBOSE);
MarketingCloudSdk.setLogListener(new MCLogListener.AndroidLogListener());
// LogManager.setLogger(BeaconLogger());
}
Log.d("Verbose", String.valueOf(MarketingCloudSdk.getLogLevel()));
SFMCSdk.configure(AppController.context, SFMCSdkModuleConfig.build(new Function1<SFMCSdkModuleConfig.Builder, Unit>() {
@Override
public Unit invoke(SFMCSdkModuleConfig.Builder builder) {
Log.d("Configuration", "call passed");
MarketingCloudSdk.init(getApplicationContext(), MarketingCloudConfig.builder()
.setApplicationId(Constant.MC_APP_ID)
.setAccessToken(Constant.MC_ACCESS_TOKEN)
.setMarketingCloudServerUrl(Constant.MC_SERVER_URL)
.setSenderId(Constant.FCM_SENDER_ID)
.setMid(Constant.MC_MID)
.setNotificationCustomizationOptions(NotificationCustomizationOptions.create(R.mipmap.app_icon, null, new com.salesforce.marketingcloud.notifications.NotificationManager.NotificationChannelIdProvider() {
@NonNull
@NotNull
@Override
public String getNotificationChannelId(@NonNull @NotNull Context context, @NonNull @NotNull NotificationMessage notificationMessage) {
// Create the NotificationChannel, but only on API 26+ because
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Marketing Channel",//Channel human readable title
NotificationManager.IMPORTANCE_DEFAULT);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
//Creating the notification object
NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext(), channelId);
notification.setAutoCancel(true);
notification.setContentTitle(notificationMessage.title());
notification.setContentText(notificationMessage.subtitle());
notification.setSmallIcon(R.mipmap.app_icon);
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pi);
int uniqueNotificationID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
//make the notification manager to issue a notification on the notification's channel
notificationManager.notify(uniqueNotificationID, notification.build());
}
return channelId;
}
}))
.setAnalyticsEnabled(true)
.setPiAnalyticsEnabled(true)
.setGeofencingEnabled(true)
.setProximityEnabled(true)
.setUseLegacyPiIdentifier(false)
.setDelayRegistrationUntilContactKeyIsSet(false)
.build(getApplicationContext()), initializationStatus -> {
if (initializationStatus.status().name().equals("FAILURE")) {
System.out.println("failed");
Log.v("MyApp", "Marketing Cloud init was successful");
} else if (initializationStatus.status().name().equals("SUCCESS")) {
Log.v("MyApp", "Marketing Cloud init was successful");
}
});
senderId
is your FCMprojectId
. There are no issues in the SDK. Follow the documentation.