Skip to content

Commit 1baff59

Browse files
authored
Update README.md
1 parent 94c2535 commit 1baff59

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ On the [Azure Portal](https://portal.azure.com) page for your notification hub,
414414

415415
The example below shows how you can register and unregister from Azure Notification Hub in your React component.
416416

417-
### Android / Windows
417+
### Windows
418418

419419
```js
420420
const NotificationHub = require('react-native-azurenotificationhub');
@@ -457,6 +457,70 @@ class myapp extends Component {
457457
}
458458
```
459459
460+
### Android
461+
462+
```js
463+
const NotificationHub = require('react-native-azurenotificationhub');
464+
const PushNotificationEmitter = new NativeEventEmitter(NotificationHub);
465+
466+
const NOTIF_REGISTER_AZURE_HUB_EVENT = 'azureNotificationHubRegistered';
467+
const NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = 'azureNotificationHubRegistrationError';
468+
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
469+
470+
const connectionString = '...'; // The Notification Hub connection string
471+
const hubName = '...'; // The Notification Hub name
472+
const senderID = '...'; // The Sender ID from the Cloud Messaging tab of the Firebase console
473+
const tags = [ ... ]; // The set of tags to subscribe to
474+
475+
class myapp extends Component {
476+
register()
477+
PushNotificationEmitter.addListener(NOTIF_REGISTER_AZURE_HUB_EVENT, this._onAzureNotificationHubRegistered);
478+
PushNotificationEmitter.addListener(NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT, this._onAzureNotificationHubRegistrationError);
479+
PushNotificationEmitter.addListener(DEVICE_NOTIF_EVENT, this._onRemoteNotification);
480+
481+
NotificationHub.register({connectionString, hubName, senderID, tags})
482+
.catch(reason => console.warn(reason));
483+
}
484+
485+
unregister() {
486+
NotificationHub.unregister()
487+
.catch(reason => console.warn(reason));
488+
}
489+
490+
render() {
491+
return (
492+
<View style={styles.container}>
493+
<TouchableOpacity onPress={this.register.bind(this)}>
494+
<View style={styles.button}>
495+
<Text style={styles.buttonText}>
496+
Register
497+
</Text>
498+
</View>
499+
</TouchableOpacity>
500+
<TouchableOpacity onPress={this.unregister.bind(this)}>
501+
<View style={styles.button}>
502+
<Text style={styles.buttonText}>
503+
Unregister
504+
</Text>
505+
</View>
506+
</TouchableOpacity>
507+
</View>
508+
);
509+
}
510+
511+
_onAzureNotificationHubRegistered(registrationID) {
512+
console.warn('RegistrationID: ' + registrationID);
513+
}
514+
515+
_onAzureNotificationHubRegistrationError(error) {
516+
console.warn('Error: ' + error);
517+
}
518+
519+
_onRemoteNotification(notification) {
520+
console.warn('Notification received: ' + notification);
521+
}
522+
```
523+
460524
### iOS
461525
462526
```js

0 commit comments

Comments
 (0)