【问题标题】:How to send a Notification for particular Android device by unique id via GCM by Windows Azure?如何通过 Windows Azure 通过 GCM 通过唯一 ID 发送特定 Android 设备的通知?
【发布时间】:2014-07-16 12:58:32
【问题描述】:

我已经使用 azure 移动服务将通知广播到 android 设备,我已收到所有通知。

但是如何通过使用唯一 ID(如 MAC-id 或 IMEI No(来自设备的任何唯一 ID))向特定设备发送通知。我已经看到 以下链接Here 但它使用了一些标签来获取通知。但我没有收到通知。

我的客户端代码是

private void registerForNotification() {
        try {
            NotificationsManager.handleNotifications(this, SENDER_ID, ClientNotificationHandler.class);
            gcm = GoogleCloudMessaging.getInstance(this);
            String connectionString = "Endpoint=sb://notifischeduler-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedKey";
            hub = new NotificationHub("notifischeduler", connectionString, this);
            if(Constant.DEBUG)
            Log.d(TAG, "Hub Details >>> "+hub.getConnectionString()+"   HUB Path >> "+hub.getNotificationHubPath());
            registerWithNotificationHubs();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @SuppressWarnings("unchecked")
    private void registerWithNotificationHubs() {
        new AsyncTask() {
            @Override
            protected Object doInBackground(Object... params) {
                try {
                    hub.unregister();
                    String regid = gcm.register(SENDER_ID);
                    String[] devArray = {"ANDROIDMOBILE2".trim()};
                    if(Constant.DEBUG)
                        Log.d(TAG,"HuB RegID  "+regid);
                    hub.register(regid,devArray);

                } catch (Exception e) {
                    e.printStackTrace();
                    return e;
                }
                return null;
            }
        }.execute(null, null, null);
    }

devArray 我需要通过唯一标识。如何做到这一点?

感谢您的帮助!

【问题讨论】:

    标签: android push-notification google-cloud-messaging android-notifications azure-mobile-services


    【解决方案1】:

    GCM 注册 ID 是识别 Android 设备的唯一 ID...

    String regId = GCMRegistrar.getRegistrationId(this);

    【讨论】:

      【解决方案2】:

      GCM 注册 ID 是识别任何 Android 设备的唯一 ID

      GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
      regId = getRegistrationId(context);
      

      然后向regId(独特的Android 设备)发送通知。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 2020-12-24
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多