简体   繁体   English

如何设置Azure通知中心注册Android的到期日期

[英]How to set expiration date for azure notification hub registration android

Hi I want to set expiry date for azure notification hub registration. 嗨,我想为Azure通知中心注册设置到期日期。 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? 您能否建议我在注册时设定有效期限的任何想法?

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 . 根据您的代码,您似乎正在使用Android的Azure NotificatonHubs SDK来实现您的需求,因此请在此处查看其javadocs。

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. 根据用于Android的Azure NotificationHubs SDK Registration的类的javadoc源代码 ,没有任何公共方法可以设置ExpirationTime来从NotificationHub对象更新Registration对象。 So it's not possible to set expiration data at the android end. 因此,无法在android端设置到期数据。

However, you can try to use the Azure NotificationHubs SDK for Java backend to do it, please refer to the backend javadocs at here . 但是,您可以尝试使用适用于Java的Azure NotificationHubs SDK后端执行此操作,请在此处参考后端javadocs。

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. 如果必须在Android端设置到期数据,我的建议是您可以尝试使用带属性registrationTtl的Notification Hubs REST API Create or Update来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM