GithubHelp home page GithubHelp logo

sandrapavankumar / azure-notificationhubs-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure/azure-notificationhubs-android

0.0 0.0 0.0 1.35 MB

Android SDK and Samples for Azure Notification Hubs

License: Apache License 2.0

Java 92.39% Shell 0.10% Kotlin 7.51%

azure-notificationhubs-android's Introduction

Azure Notification Hubs - Android SDK

Azure Notification Hubs (ANH) provides a multi-platform, scaled-out push infrastructure that enables you to send mobile push notifications from any backend (in the cloud or on-premises) to any mobile platform. To learn more, visit our Developer Center.

Getting Started with ANH Android SDK

To use ANH in your Android application, you'll need to accomplish a few things:

  1. Ensure your application is registered with Firebase.
  2. Add a reference to this library in your build.gradle.
  3. Add your hub's credentials to your application.

Below is a quick overview of these steps, for a more complete tutorial see our FCM tutorials.

Register with Firebase

One of the primary goals of ANH is to provide an abstraction over platform specific notification delivery services, it is not an alternative. In order to make sure your application is set up to receive push notifications from Firebase, follow steps 1 through 3 in this Firebase set up tutorial.

Once you have a Firebase project, and your application registered, make sure to configure the API Key in your Notification Hub. Instructions can be found here.

Reference with Gradle

This library is published on JFrog Bintray. Adding a reference to this project is as simple as editting two files in your project:

{project-root}/build.gradle:

// This is not a complete build.gradle file, it only highlights the portions you'll need to use ANH.

allprojects {
    repositories {
        // Ensure you have the following repsoitory in your "allprojects", "repositories" section.
        maven {
            url 'https://dl.bintray.com/microsoftazuremobile/SDK'
        }
    }
}

{project-root}/{your-module}/build.gradle:

// This is not a complete build.gradle file, it only highlights the portions you'll need to use ANH.

dependencies {
    // Ensure the following line is included in your app/library's "dependencies" section.
    implementation 'com.microsoft.azure:notification-hubs-android-sdk:v1.1.1'
}

Embedding Hub Credentials

In order to connect to your Notification Hub, you'll need to embed the key from an access signature into your application. Remember, client applications should always use the Listen only access signature. Step six in this section shows you how to fetch the access signature from the Azure portal.

The easiest way to embed your ANH credentials without commiting them to source control is to use BuildConfig to convert environment variables into a runtime field:

{project-root}/{your-module}/build.gradle:

// This is not a complete build.gradle file, it only highlights the portions you'll need to use ANH.

android {
    defaultConfig {
        // Populates BuildConfig.hubName with the value that was stored APP_HUB_NAME at build time.
        buildConfigField("String", "hubName", "\"${System.getenv('APP_HUB_NAME') ?: secretsProperties['APP_HUB_NAME']}\"")
        //Populates BuildConfig.hubListenConnectionString with the value that was stored in APP_NH_CONNECTION_STRING at build time.
        buildConfigField("String", "hubListenConnectionString", "\"${System.getenv('APP_NH_CONNECTION_STRING') ?: secretsProperties['APP_NH_CONNECTION_STRING']}\"")
    }
}

This will enable you to use the following line to initialize the library:

MainActivity.java:

NotificationHub.start(this.getApplication(), BuildConfig.hubName, BuildConfig.hubListenConnectionString);

Repository Contents

The code found in this namespace uses ANH's Installation flow. It is heavily influenced by App Center Push's SDK. It was designed to do more than just act as a REST client, instead abstracting away your interactions with ANH. New projects that are looking to use ANH should use the constructs found in this namespace.

Some highlights of the functionality provided in this namespace:

  • With one line of initialization code, this library will automatically and asynchronously call the Notification Hub backend anytime device details change.
  • Easily register a callback to receive Firebase Cloud Messaging notifications.
  • Highly customizable pipeline to ensure your device always has the properties you find most useful.

This is our SDK's legacy codebase. It facilitates interactions with our Registration flow. This namespace contains code that does little more than act as a REST client. Customers newly using ANH should NOT use the code found in this namespace. Expect it to be deprecated.

This is a sample application built on com.microsoft.windowsazure.messaging.notificationhubs. It was built to represent current best practices, and demonstrate how to get off the ground with ANH. If you're looking to experiment with ANH, this is a good app to get started with, to see what it can do.

This application demonstrates how to use the Registration flow using com.microsoft.windowsazure.messaging. If older tutorials or blogs (published before August, 2020) don't otherwise specify, this is likely the sample application they are referring to.

This application demostrates the final product of a person freshly completing this tutorial. When there is a discrepancy between the tutorial and this application, try running the application here to see if it has the desired behavior.

This is an old-school test harness to execute unit tests on com.microsoft.windowsazure.messaging from before there was a more sophististicated environment for executing tests in an Android environment.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-notificationhubs-android's People

Contributors

aimankhan avatar alessar avatar brannon avatar carlpoole avatar dmitrydibenko avatar efimovandr avatar fsautomata avatar itoys avatar jwargo avatar kmiecikt avatar kostya-zhidovinov avatar kylekampy avatar leotilli avatar louismagdaleno avatar marianosz avatar marstr avatar mehrdadmzfr avatar microsoftopensource avatar mpodwysocki avatar msftgits avatar olgaakv avatar polinabarv avatar smithaborkar avatar stankovski avatar v-fekalu avatar varvusc avatar ysxu avatar zhangeugenia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.