How to set expiration date for azure notification hub registration android

1.1k views Asked by At

Hi I want to set expiry date for azure notification hub registration. I use the below line for notification hub registration,

 NotificationHub hub = new NotificationHub(mGCMPreferences.getHubName(), mGCMPreferences.getConnectionString(), mContext);
 String registerId = hub.register(token, mGCMPreferences.getTagId()).getRegistrationId();

Could you please suggest me any idea to set expiry date while registration?

1

There are 1 answers

0
Peter Pan On

According to your code, it seems that you were using Azure NotificatonHubs SDK for Android to implement your needs, so please view its javadocs at here.

According to the javadoc & source code for class Registration of Azure NotificationHubs SDK for Android, there is not any public method for setting ExpirationTime to update the the Registration object from NotificationHub object. So it's not possible to set expiration data at the android end.

However, you can try to use the Azure NotificationHubs SDK for Java backend to do it, please refer to the backend javadocs at here.

As reference, here is a sample code.

String connectionString = "<your connection string>";
String hubPath = "<your hub path>";
NotificationHub hub = new NotificationHub(connectionString, hubPath);
// Get the registration by Id
String registrationId = "<your registration id>";
Registration registration = hub.getRegistration(registrationId);
// Set the expiration date
Date expirationTime = new Date(....);
registration.setExpirationTime(expirationTime);

If you have to set the expiration data at the Android end, my suggestion is that you can try to use the Notification Hubs REST API Create or Update with the property registrationTtl to do it.