【Azure Notification Hub】实验Notification Hub页面中的Test Tag 功能 -- 定向发送消息到指定的Android设备

问题描述

使用Notification Hub(通知中心)发送移动设备的通知,在Azure Notification Hub页面,可以通过Test功能测试设备是否可以成功收到消息。

只是,这个页面只能随机发送10个设备,如果设备超过10个之后,当需要定向指定发送到某一个/某一类设备时,就无法达到快速的测试目的。

You can send test notifications to a specific set of registrations using this option. Leave this field empty if you like to send push notifications to 10 random registrations on the selected platform

image

本文就将通过为设备配置Tag之后,在当前Test页面指定Tag值来实现这一目的。

问题解答

第一步:在向Notification Hub注册设备的时候,就需要为这个设备添加Tag,代码如下:

private void registerWithNotificationHubs() {

        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    //String[] tags ={"thislubutest"};
                    String[] tags ={"pixel1api35"};
                    hub.registerBaidu(mUserId, mChannelId,tags);
                    Log.i(TAG, "Registered with Notification Hub - '"
                            + ConfigurationSettings.NotificationHubName + "'"
                            + " with UserId - '"
                            + mUserId + "' and Channel Id - '"
                            + mChannelId + "'");
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage());
                }
                return null;
            }
        }.execute(null, null, null);
    }

第二步:在Test Send中,把注册设备时使用的tags值写入 “ ” 

image

 

 

参考资料

 

 

posted @ 2025-12-24 22:04  路边两盏灯  阅读(1)  评论(0)    收藏  举报