Git Product home page Git Product logo

pushstarter-android-app's Introduction

Android Push Template


Author: Daniel Passos ([email protected], [email protected])
Level: Intermediate
Technologies: Java, Android, RHMAP, GCM Push Messages
Summary: A demonstration of how to receive a GCM push message from RHMAP
Community Project : Feed Henry
Target Product: RedHat Mobile Application Platform aka RHMAP
Product Versions: RHMAP 3.8.0+
Source: https://github.com/feedhenry-templates/pushstarter-android-app
Prerequisites: fh-android-sdk : 3.0.+, Android Studio : 1.4.0 or newer, Android SDK : 22+ or newer

What is it?

This application will subscribe to a push service running in a RHMAP instance. The user can send messages to the device using RHMAP and view them on the device.

If you do not have access to a RHMAP instance, you can sign up for a free instance at https://openshift.feedhenry.com/.

How do I run it?

RHMAP Studio

You can create this project as a template inside of RHMAP Studio. The full tutorial for setting up AeroGear UPS, registering on the Google Cloud Messaging network, and using the app can be found on the RedHat Mobile docs site.

Firebase Cloud Messaging

  • You need to have a valid Firebase Cloud Messaging project setup. Download the google-services.json file from the Firebase Console and put it into the app directory of your Android Application.
  • You also need to use the package from the Firebase Cloud Messaging configuration as the package for your application.

Build instructions for Open Source Development

If you wish to contribute to this template, the following information may be helpful; otherwise, RHMAP and its build facilities are the preferred solution.

Build instructions

  • Edit fhconfig.properties to include the relevant information from RHMAP.
  • Attach running Android Device with API 16+ running
  • ./gradlew installDebug

How does it work?

Registration With Messaging Services

In RegisterActivity there is the following block of code :

FH.pushRegister(new FHActCallback() {
            @Override
            public void success(FHResponse fhResponse) {
                startActivity(new Intent(RegisterActivity.this, MessagesActivity.class));
            }

            @Override
            public void fail(FHResponse fhResponse) {
                Toast.makeText(getApplicationContext(),
                        fhResponse.getErrorMessage(), Toast.LENGTH_SHORT).show();
                finish();
            }
        });

This code will register the device with both AeroGear UnifiedPush Service AND Google's GCM network. If both actions are successful then it will launch the main activity. Otherwise it will display an error and quit.

Handling messages

Messages are handled by implementations of the MessageHandler interface which are registered with the RegistrarManager. These classes are MessagesActivity and NotificationBarMessageHandler.

In the MessagesActivity class the Activity switches between itself and the NotificationBarMessageHandler in the onPause and onResume methods.

 @Override
    protected void onResume() {
        super.onResume();
        RegistrarManager.registerMainThreadHandler(this);
        RegistrarManager.unregisterBackgroundThreadHandler(NotificationBarMessageHandler.instance);

        displayMessages();
    }

    @Override
    protected void onPause() {
        super.onPause();
        RegistrarManager.unregisterMainThreadHandler(this);
        RegistrarManager.registerBackgroundThreadHandler(NotificationBarMessageHandler.instance);
    }

pushstarter-android-app's People

Contributors

corinnekrych avatar danielpassos avatar david-martin avatar matzew avatar secondsun avatar

Watchers

 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.