Keine Ergebnisse gefunden

Probeer een andere of meer specifieke zoekopdracht
Developer Console
Vielen Dank für deinen Besuch. Diese Seite ist nur in Englisch verfügbar.

A3L Messaging Sample App

This page walks you through a sample app built using the A3L Messaging SDK. The purpose of the app is to demonstrate how to integrate with A3L Messaging. To run this app, you don't need to write any code, but you must provide the configurations. You can install the app on both Google Play-enabled devices and Fire OS devices. From the app, you can send a push notification to the device on which it is installed. To a send push notification, the app requires server-side credentials.

Download the sample app project

Download the sample A3L messaging app to get started. The file contains an Android project which you can use to configure and build the sample app.

When building the project, if you run into an "SDK location not found" error, add a line in the local.properties file at the root of the project to include your Android SDK location.

For example:

  • On Windows, add the line: sdk.dir=C:\\Users\\{username}\\AppData\\Local\\Android\\sdk
  • On Mac, add the line: sdk.dir=/Users/{username}/Library/Android/sdk

Replace {username} with your username.

Sample app integration

The sample app requires both device-side credentials as well as server-side credentials. Device-side credentials are present in the app and are required for cloud messaging to work. Typically, server-side credentials should be used in a secure server environment. However, for demonstration, this app uses server-side credentials in the app itself. In a real project, don't use server-side credentials in the app, as this wouldn't be secure.

There are four configuration files which you must populate for the sample app to run.

File name Location Configuration type Messaging type
api_key.txt
To obtain, see step 1 in Device-side configuration.
app/src/main/assets/ Device-side ADM
adm_server_configuration.json
To obtain, see step 1 in Server-side configuration.
app/src/main/assets/ Server-side ADM
google-services.json
To obtain, see step 2 in Device-side configuration.
app/ Device-side FCM
fcm_server_configuration.json
To obtain, see 2 in Server-side configuration.
app/src/main/assets/ Server-side FCM

The sample app's integration guide is divided into two parts: device-side configuration and server-side configuration.

Device-side configuration

First, obtain device-side configurations for both Amazon Device Messaging (ADM) and Firebase Cloud Messaging (FCM).

While generating credentials, you might need to provide the package name of your app. The sample app's package name is com.example.SampleA3LMessagingApp.

  1. For ADM, go to the Developer Console and obtain your credentials. Then add an API key to your project. Be sure to enable device messaging for your app by attaching the security profile under the App Services section of your app in the Developer Console.

  2. For FCM, create a Firebase project and register your app with Firebase. Obtain a google-services.json configuration file and add the file to your project.

Server-side configuration

Next, obtain server-side configurations for ADM and FCM.

  1. For ADM, add the client ID and client secret to the adm_server_configuration.json, which is present under the assets folder. An example ADM server configuration JSON follows.

     {
         "client_id": "Client Id",
         "client_secret": "Client Secret"
     }
    
  2. For FCM, create a Google service account key and follow the instructions to download the key as a JSON file. You can also use an existing service account key. Copy the content of the downloaded JSON and paste it into fcm_server_configuration.json, located under the assets folder. An example FCM server configuration JSON follows.

     {
         "type": "service_account",
         "project_id": "PROJECT_ID",
         "private_key_id": "KEY_ID",
         "private_key": "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n",
         "client_email": "SERVICE_ACCOUNT_EMAIL",
         "client_id": "CLIENT_ID",
         "auth_uri": "https://accounts.google.com/o/oauth2/auth",
         "token_uri": "https://accounts.google.com/o/oauth2/token",
         "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
         "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL"
     }
    

Sample app testing

  1. After configuring all four configuration files, build the app.
  2. Install the app on an Android device that has the Google Play Service enabled or on a Fire OS device.
  3. Open the app. You should see a welcome page with debug placeholder text and a SEND PUSH NOTIFICATION button.
  4. Click SEND PUSH NOTIFICATION. A toast message instructing you to check the notification tray should appear. You should also see a debug statement containing the device ID where the placeholder text was previously.
  5. Check the notification tray of the device to make sure the message was successfully delivered.
    a push notification message from a sample app
    A successfully delivered notification

Last updated: Jun 06, 2022