Skip to content

Commit 2f660b0

Browse files
author
Delora Bradish
committed
added Azure CLI syntax for Google FCM
1 parent 6878840 commit 2f660b0

File tree

1 file changed

+67
-18
lines changed

1 file changed

+67
-18
lines changed

articles/notification-hubs/configure-notification-hub-portal-pns-settings.md

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Azure Notification Hubs provides a push engine that's easy to use and that scale
2121

2222
In this quickstart, you'll use the platform notification system (PNS) settings in Notification Hubs to set up push notifications on multiple platforms. The quickstart shows you the steps to take in the Azure portal.
2323

24-
If you haven't already created a notification hub, create one now. For more information, see [Create an Azure notification hub in the Azure portal](create-notification-hub-portal.md).
24+
If you haven't already created a notification hub, create one now. For more information, see [Create an Azure notification hub in the Azure portal](create-notification-hub-portal.md).
2525

2626
## Apple Push Notification Service
2727

@@ -49,18 +49,67 @@ For more information, see [Push notifications to iOS by using Azure Notification
4949

5050
## Google Firebase Cloud Messaging
5151

52+
# [Portal](#tab/azure-portal)
53+
5254
To set up push notifications for Google Firebase Cloud Messaging (FCM):
5355

54-
1. In the Azure portal, on the **Notification Hub** page, select **Google (GCM/FCM)** from the left menu.
55-
2. Paste the **API Key** for the FCM project that you saved earlier.
56-
3. Select **Save**.
56+
1. In the Azure portal, on the **Notification Hub** page, select **Google (GCM/FCM)** from the left menu.
57+
2. Paste the **API Key** for the FCM project that you saved earlier.
58+
3. Select **Save**.
5759

5860
![Screenshot that shows how to configure Notification Hubs for Google FCM](./media/notification-hubs-android-push-notification-google-fcm-get-started/fcm-server-key.png)
5961

60-
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The **Save** button is disabled.
62+
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The **Save** button is disabled.
6163

6264
For more information, see [Push notifications to Android devices by using Notification Hubs and Google FCM](notification-hubs-android-push-notification-google-fcm-get-started.md).
6365

66+
# [Azure CLI](#tab/azure-cli)
67+
68+
### Prerequisites
69+
70+
Before you begin, you must have the following:
71+
72+
* The [Azure CLI](/cli/azure/install-azure-cli) version 2.0.67 or later.
73+
74+
* The Azure CLI [extension for Notification Hubs](/cli/azure/ext/notification-hub/notification-hub).
75+
* The **API Key** for a Google Firebase Cloud Messaging (FCM) project.
76+
77+
### Set up push notifications for Google Firebase Cloud Messaging (FCM)
78+
79+
1. Use the [az notification-hub credential gcm update](/cli/azure/ext/notification-hub/notification-hub/credential/gcm#ext-notification-hub-az-notification-hub-credential-gcm-update) command to add your Google API Key to your notification hub.
80+
81+
```azurecli
82+
az notification-hub credential gcm update --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --google-api-key myKey
83+
```
84+
85+
2. The Android App needs a connection string to connect with the notification hub. Use the [az notification-hub authorization-rule list](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list) command to list the available access policies. Run the [az notification-hub authorization-rule list-keys](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list-keys) command to get the access policy connection strings. Specify the **primaryConnectionString** or **secondaryConnectionString** in the `--query` parameter to get the primary connection string directly.
86+
87+
```azurecli
88+
#list access policies for a notification hub
89+
az notification-hub authorization-rule list --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --output table
90+
91+
#list keys and connection strings for a notification hub access policy
92+
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name myAccessPolicyName --output json
93+
94+
#get the primaryConnectionString for an access policy
95+
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name myAccessPolicyName --query primaryConnectionString
96+
```
97+
98+
3. Use the [az notification-hub test-send](/cli/azure/ext/notification-hub/notification-hub#ext-notification-hub-az-notification-hub-test-send) command to test sending messages to the Android App.
99+
100+
```azurecli
101+
#test with message body
102+
az notification-hub test-send --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --notification-format gcm --message "test notification"
103+
104+
#test with JSON string
105+
az notification-hub test-send --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --notification-format gcm --payload "{\"data\":{\"message\":\"test notification\"}}"
106+
```
107+
108+
> [!NOTE]
109+
> Get Azure CLI references for other platforms with the [az notification-hub credential](/cli/azure/ext/notification-hub/notification-hub/credential) command.
110+
111+
---
112+
64113
## Windows Push Notification Service
65114

66115
To set up Windows Push Notification Service (WNS):
@@ -75,7 +124,7 @@ For information, see [Send notifications to UWP apps by using Azure Notification
75124

76125
## Microsoft Push Notification Service for Windows Phone
77126

78-
To set up Microsoft Push Notification Service (MPNS) for Windows Phone:
127+
To set up Microsoft Push Notification Service (MPNS) for Windows Phone:
79128

80129
1. In the Azure portal, on the **Notification Hub** page, select **Windows Phone (MPNS)** from the left menu.
81130
1. Enable either unauthenticated or authenticated push notifications:
@@ -92,30 +141,30 @@ To set up Microsoft Push Notification Service (MPNS) for Windows Phone:
92141
* On the **Windows Phone (MPNS)** page, select **Save**.
93142

94143
For more information, see [Push notifications to Windows Phone apps by using Notification Hubs](notification-hubs-windows-mobile-push-notifications-mpns.md).
95-
96144

97145
## Baidu (Android China)
98146

99147
To set up push notifications for Baidu:
100148

101-
1. In the Azure portal, on the **Notification Hub** page, select **Baidu (Android China)** from the left menu.
102-
2. Enter the **Api Key** that you obtained from the Baidu console in the Baidu cloud push project.
103-
3. Enter the **Secret Key** that you obtained from the Baidu console in the Baidu cloud push project.
104-
4. Select **Save**.
149+
1. In the Azure portal, on the **Notification Hub** page, select **Baidu (Android China)** from the left menu.
150+
2. Enter the **Api Key** that you obtained from the Baidu console in the Baidu cloud push project.
151+
3. Enter the **Secret Key** that you obtained from the Baidu console in the Baidu cloud push project.
152+
4. Select **Save**.
105153

106154
![Screenshot of Notification Hubs that shows the Baidu (Android China) configuration for push notifications](./media/notification-hubs-baidu-get-started/AzureNotificationServicesBaidu.png)
107155

108-
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The **Save** button is disabled.
156+
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The **Save** button is disabled.
109157

110158
For more information, see [Get started with Notification Hubs by using Baidu](notification-hubs-baidu-china-android-notifications-get-started.md).
111159

112160
## Next steps
113-
In this quickstart, you learned how to configure platform notification system settings for a notification hub in the Azure portal.
161+
162+
In this quickstart, you learned how to configure platform notification system settings for a notification hub in the Azure portal.
114163

115164
To learn more about how to push notifications to various platforms, see these tutorials:
116165

117-
- [Push notifications to iOS devices by using Notification Hubs and APNS](notification-hubs-ios-apple-push-notification-apns-get-started.md)
118-
- [Push notifications to Android devices by using Notification Hubs and Google FCM](notification-hubs-android-push-notification-google-fcm-get-started.md)
119-
- [Push notifications to a UWP app running on a Windows device](notification-hubs-windows-store-dotnet-get-started-wns-push-notification.md)
120-
- [Push notifications to a Windows Phone 8 app by using MPNS](notification-hubs-windows-mobile-push-notifications-mpns.md)
121-
- [Push notifications by using Notification Hubs and Baidu cloud push](notification-hubs-baidu-china-android-notifications-get-started.md)
166+
-[Push notifications to iOS devices by using Notification Hubs and APNS](notification-hubs-ios-apple-push-notification-apns-get-started.md)
167+
-[Push notifications to Android devices by using Notification Hubs and Google FCM](notification-hubs-android-push-notification-google-fcm-get-started.md)
168+
-[Push notifications to a UWP app running on a Windows device](notification-hubs-windows-store-dotnet-get-started-wns-push-notification.md)
169+
-[Push notifications to a Windows Phone 8 app by using MPNS](notification-hubs-windows-mobile-push-notifications-mpns.md)
170+
-[Push notifications by using Notification Hubs and Baidu cloud push](notification-hubs-baidu-china-android-notifications-get-started.md)

0 commit comments

Comments
 (0)