Skip to content

Commit 33cc29d

Browse files
authored
Merge pull request #87555 from andrewwang2015/andrwan/android-fcm-updates
Add updates to NH Tutorials for Android FCM
2 parents 494d4f8 + 31c71a7 commit 33cc29d

7 files changed

+38
-21
lines changed
Loading
Loading
Loading

articles/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ms.tgt_pltfrm: mobile-android
1515
ms.devlang: java
1616
ms.topic: tutorial
1717
ms.custom: mvc
18-
ms.date: 07/15/2019
18+
ms.date: 09/11/2019
1919
ms.author: jowargo
2020
---
2121

@@ -186,7 +186,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
186186
> [!IMPORTANT]
187187
> Enter the **name** and the **DefaultListenSharedAccessSignature** of your hub before proceeding further.
188188

189-
3. Add another new class to your project named `RegistrationIntentService`. This class implements the `IntentService` interface. It also handles [refreshing the FCM token](https://developers.google.com/instance-id/guides/android-implementation#refresh_tokens) and [registering with the notification hub](notification-hubs-push-notification-registration-management.md).
189+
2. Add another new class to your project named `RegistrationIntentService`. This class implements the `IntentService` interface. It also handles [refreshing the FCM token](https://developers.google.com/instance-id/guides/android-implementation#refresh_tokens) and [registering with the notification hub](notification-hubs-push-notification-registration-management.md).
190190

191191
Use the following code for this class.
192192

@@ -288,7 +288,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
288288
}
289289
```
290290

291-
4. In the `MainActivity` class, add the following `import` statements above the class declaration.
291+
3. In the `MainActivity` class, add the following `import` statements above the class declaration.
292292

293293
```java
294294
import com.google.android.gms.common.ConnectionResult;
@@ -299,7 +299,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
299299
import android.widget.Toast;
300300
```
301301

302-
5. Add the following members at the top of the class. You use these fields to [check the availability of Google Play Services as recommended by Google](https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk).
302+
4. Add the following members at the top of the class. You use these fields to [check the availability of Google Play Services as recommended by Google](https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk).
303303

304304
```java
305305
public static MainActivity mainActivity;
@@ -308,7 +308,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
308308
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
309309
```
310310

311-
6. In the `MainActivity` class, add the following method to check the availability of Google Play Services.
311+
5. In the `MainActivity` class, add the following method to check the availability of Google Play Services.
312312

313313
```java
314314
/**
@@ -335,7 +335,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
335335
}
336336
```
337337

338-
7. In the `MainActivity` class, add the following code that checks for Google Play Services before calling the `IntentService` to get your FCM registration token and register with your hub:
338+
6. In the `MainActivity` class, add the following code that checks for Google Play Services before calling the `IntentService` to get your FCM registration token and register with your hub:
339339

340340
```java
341341
public void registerWithNotificationHubs()
@@ -348,7 +348,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
348348
}
349349
```
350350

351-
8. In the `OnCreate` method of the `MainActivity` class, add the following code to start the registration process when the activity is created:
351+
7. In the `OnCreate` method of the `MainActivity` class, add the following code to start the registration process when the activity is created:
352352

353353
```java
354354
@Override
@@ -362,7 +362,7 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
362362
}
363363
```
364364

365-
9. To verify app state and report status in your app, add these additional methods to `MainActivity`:
365+
8. To verify app state and report status in your app, add these additional methods to `MainActivity`:
366366

367367
```java
368368
@Override
@@ -401,15 +401,17 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
401401
}
402402
```
403403

404-
10. The `ToastNotify` method uses the *"Hello World"* `TextView` control to report status and notifications persistently in the app. In your **res** > **layout** > **activity_main.xml** layout, add the following ID for that control.
404+
9. The `ToastNotify` method uses the *"Hello World"* `TextView` control to report status and notifications persistently in the app. In your **res** > **layout** > **activity_main.xml** layout, add the following ID for that control.
405405

406406
```java
407407
android:id="@+id/text_hello"
408408
```
409409

410-
11. Next you add a subclass for the receiver that you defined in AndroidManifest.xml. Add another new class to your project named `FirebaseService`.
410+
![Azure Notification Hubs - Test Send](./media/notification-hubs-android-push-notification-google-fcm-get-started/activity-main-xml.png)
411411

412-
12. Add the following import statements at the top of `FirebaseService.java`:
412+
10. Next you add a subclass for the receiver that you defined in AndroidManifest.xml. Add another new class to your project named `FirebaseService`.
413+
414+
11. Add the following import statements at the top of `FirebaseService.java`:
413415

414416
```java
415417
import com.google.firebase.messaging.FirebaseMessagingService;
@@ -424,10 +426,10 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
424426
import android.net.Uri;
425427
import android.os.Build;
426428
import android.os.Bundle;
427-
import android.support.v4.app.NotificationCompat;
429+
import androidx.core.app.NotificationCompat;
428430
```
429431

430-
13. Add the following code for the `FirebaseService` class, making it a subclass of `FirebaseMessagingService`.
432+
12. Add the following code for the `FirebaseService` class, making it a subclass of `FirebaseMessagingService`.
431433

432434
This code overrides the `onMessageReceived` method and reports notifications that are received. it also sends the push notification to the Android notification manager by using the `sendNotification()` method. Call the `sendNotification()` method when the app isn't running and a notification is received.
433435

@@ -514,12 +516,16 @@ Your hub is now configured to work with Firebase Cloud Messaging. You also have
514516
}
515517
```
516518

517-
14. In Android Studio, on the menu bar, select **Build** > **Rebuild Project** to make sure that there aren't any errors in your code. If you receive an error about the `ic_launcher` icon, remove the following statement from the AndroidManifest.xml file:
519+
13. In Android Studio, on the menu bar, select **Build** > **Rebuild Project** to make sure that there aren't any errors in your code. If you receive an error about the `ic_launcher` icon, remove the following statement from the AndroidManifest.xml file:
518520

519521
```
520522
android:icon="@mipmap/ic_launcher"
521523
```
522-
15. Run the app on your device and verify that it registers successfully with the hub.
524+
14. Ensure you have a virtual device for running the app. If you do not have one, add one as follows:
525+
1. ![Open device manager](./media/notification-hubs-android-push-notification-google-fcm-get-started/open-device-manager.png)
526+
2. ![Create virtual device](./media/notification-hubs-android-push-notification-google-fcm-get-started/your-virtual-devices.PNG)
527+
528+
15. Run the app on your selected device and verify that it registers successfully with the hub.
523529

524530
> [!NOTE]
525531
> Registration might fail during the initial launch until the `onTokenRefresh()` method of the instance ID service is called. The refresh should initiate a successful registration with the notification hub.

articles/notification-hubs/push-notifications-android-specific-users-firebase-cloud-messaging.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ms.tgt_pltfrm: mobile-android
1414
ms.devlang: java
1515
ms.topic: tutorial
1616
ms.custom: mvc
17-
ms.date: 05/01/2019
17+
ms.date: 09/11/2019
1818
ms.author: jowargo
1919
---
2020

@@ -466,7 +466,14 @@ The next step is to update the Android application created in the [Tutorial: Pus
466466
```java
467467
useLibrary 'org.apache.http.legacy'
468468
```
469-
13. Build the project.
469+
13. If your app is targeting API level 28 (Android 9.0) or above, include the following declaration within the `<application>` element of `AndroidManifest.xml`.
470+
471+
```xml
472+
<uses-library
473+
android:name="org.apache.http.legacy"
474+
android:required="false" />
475+
```
476+
14. Build the project.
470477

471478
## Test the app
472479

includes/notification-hubs-aspnet-backend-notifyusers.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
author: spelluru
66
ms.service: notification-hubs
77
ms.topic: include
8-
ms.date: 03/22/2019
8+
ms.date: 09/11/2019
99
ms.author: spelluru
1010
ms.custom: include file
1111
---
@@ -180,6 +180,9 @@ In this section, you add a new controller to the WebAPI backend to handle reques
180180
}
181181
}
182182
```
183+
> [!IMPORTANT]
184+
> Enter the **name** and the **DefaultFullSharedAccessSignature** of your hub before proceeding further.
185+
183186
7. Next, create a new controller named **RegisterController**. In Solution Explorer, right-click the **Controllers** folder, select **Add**, and then select **Controller**.
184187

185188
8. Select **Web API 2 Controller - Empty**, and then select **Add**.

includes/notification-hubs-enable-firebase-cloud-messaging.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
author: spelluru
66
ms.service: notification-hubs
77
ms.topic: include
8-
ms.date: 02/05/2019
8+
ms.date: 09/11/2019
99
ms.author: spelluru
1010
ms.custom: include file
1111
---
@@ -28,10 +28,11 @@
2828
```
2929
classpath 'com.google.gms:google-services:4.0.1'
3030
```
31-
2. In your app-level build.gradle file (&lt;project&gt;/&lt;app-module&gt;/build.gradle), add the following statement to the **dependencies** section.
31+
2. In your app-level build.gradle file (&lt;project&gt;/&lt;app-module&gt;/build.gradle), add the following statements to the **dependencies** section.
3232
3333
```
34-
implementation 'com.google.firebase:firebase-core:16.0.1'
34+
implementation 'com.google.firebase:firebase-core:16.0.8'
35+
implementation 'com.google.firebase:firebase-messaging:17.3.4'
3536
```
3637
3738
3. Add the following line to the end of the app-level build.gradle file after the dependencies section.

0 commit comments

Comments
 (0)