Hey! These docs are for version 7.0, which is no longer officially supported. Click here for the latest version, 9.0!

Amazon SDK Setup

Instructions for adding the OneSignal SDK to your Amazon app

Required For Setup

Setup SDK in Android Studio

Android Studio is the most common way to build Amazon projects.

1. Follow our Android Studio Setup

1.1 Follow our Android SDK Setup guide for Android Studio and return to back to this guide once completed.

2. Update AndroidManifest.xml

2.1. Open your AndroidManifest.xml file and add xmlns:amazon="http://schemas.amazon.com/apk/res/android" in the manifest tag right after the xmlns:android property.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:amazon="http://schemas.amazon.com/apk/res/android"
    package="com.onesignal.example"
    android:versionCode="1"
    android:versionName="1.0" >

2.2. Add the following permissions to AndroidManifest.xml:

<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" />

2.3. In the application tag, add the following:

<application ....>
  <amazon:enable-feature android:name="com.amazon.device.messaging"
                         android:required="false"/>
  <service android:name="com.onesignal.ADMMessageHandler"
           android:exported="false" />
  <service android:name="com.onesignal.ADMMessageHandlerJob"
           android:permission="android.permission.BIND_JOB_SERVICE"
           android:exported="false" />
  <receiver android:name="com.onesignal.ADMMessageHandler$Receiver"
            android:permission="com.amazon.device.messaging.permission.SEND" >
    <intent-filter>
      <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
      <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
      <category android:name="COM.YOUR.PACKAGE_NAME" />
    </intent-filter>
  </receiver>
  
</application>

2.4. Replace all 3 of instances COM.YOUR.PACKAGE_NAME with your package name in AndroidManifest.xml.

3. Amazon API Key File

3.1 Place your api_key.txt in a folder named assets in the root of your project.

506

To create an api_key.txt for your app, follow our Generate an Amazon API Key guide.

3.2 Make sure to use the same keystore when building your APK as you did in step 2.4 in the Amazon Configuration guide.

3.3. Ensure that you are not building a debug app when testing Amazon push notifications. It must be a release type.

387

Setup SDK in Eclipse

Eclipse is a less common way to build Amazon projects.

🚧

Android Setup

If your app is also on the Google Play Store or is available for non-Amazon Android devices on the Amazon Appstore, then make sure to also follow our Android SDK Setup Guide so that users in those markets are not left out.

1. Import Libraries

1.1 Download the latest OneSignal Android SDK.

1.2. Copy <android-sdk>\extras\android\support\v4\android-support-v4.jar into your project's libs folder. If you're missing it, run the Android SDK Manager and install it from the Extras section.

SDK Path: is shown on this window. Replace <android-sdk> with your path.

600

1.3. Copy OneSignalSDK.jar from our SDK, and place it in your project's libs folder as well.

217

2. Add Required Code

If you have already followed our Android Native Guide, you can skip to step 3.

2.1. Import OneSignal.

import com.onesignal.OneSignal;
import com.onesignal.OneSignal.NotificationOpenedHandler;

2.2. Add the following to the onCreate method on your main activity.

// Pass in your app's Context, optional Google Project Number, your OneSignal App ID, and NotificationOpenedHandler
OneSignal.init(this, "", "5eb5a37e-b458-11e3-ac11-000c2940e62c", new ExampleNotificationOpenedHandler());

Update 5eb5a37e-b458-11e3-ac11-000c2940e62c with your OneSignal AppID.

Replace the the 2nd parameter with your Google Project number if your app is also on the Google Play Store.

2.3. Add the following private class in your activity (or in its own class file).

// This fires when a notification is opened by tapping on it.
private class ExampleNotificationOpenedHandler implements NotificationOpenedHandler {
  @Override
  public void notificationOpened(OSNotificationOpenResult openedResult) {
    OSNotificationAction.ActionType actionType = openedResult.action.type;
    JSONObject data = openedResult.notification.payload.additionalData;

    String customKey = data.optString("customkey", null);
    if (actionType == OSNotificationAction.ActionType.ActionTaken)
      Log.i("OneSignalExample", "Button pressed with id: " + openedResult.action.actionID);

    // The following can be used to open an Activity of your choice.
    /*
      Intent intent = new Intent(getApplication(), YourActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
      */
    // Follow the instructions in the link below to prevent the launcher Activity from starting.
    // https://documentation.onesignal.com/docs/android-notification-customizations#changing-the-open-action-of-a-notification
}

3. Update AndroidManifest.xml

3.1. Open your AndroidManifest.xml file and add xmlns:amazon="http://schemas.amazon.com/apk/res/android" in the manifest tag right after the xmlns:android property.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:amazon="http://schemas.amazon.com/apk/res/android"
    package="com.onesignal.example"
    android:versionCode="1"
    android:versionName="1.0" >

3.2. Add the following permissions to AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- START: ShortcutBadger -->
<!-- Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>

<!-- HTC -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT"/>

<!-- Sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE"/>
<uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE"/>

<!-- Apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>

<!-- Solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>

<!-- Huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />

<!-- ZUK -->
<uses-permission android:name="android.permission.READ_APP_BADGE"/>

<!-- OPPO -->
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS"/>

<!-- EvMe -->
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ"/>
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE"/>

<!-- End: ShortcutBadger -->

3.3. In the application tag, add the following:

<application ....>
  <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false"/>
  <activity android:name="com.onesignal.NotificationOpenedActivity" android:theme="@android:style/Theme.NoDisplay"/>
  <service android:name="com.onesignal.ADMMessageHandler" android:exported="false" />
  <receiver android:name="com.onesignal.ADMMessageHandler$Receiver"
            android:permission="com.amazon.device.messaging.permission.SEND" >
    <intent-filter>
      <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
      <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
      <category android:name="COM.YOUR.PACKAGE_NAME" />
    </intent-filter>
  </receiver>
  <receiver android:name="com.onesignal.NotificationOpenedReceiver" />
  <service android:name="com.onesignal.GcmIntentService" />
  <service android:name="com.onesignal.SyncService" android:stopWithTask="false" />
  <activity android:name="com.onesignal.PermissionsActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
  
  <service android:name="com.onesignal.NotificationRestoreService" />
  <receiver android:name="com.onesignal.BootUpReceiver">
    <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
  </receiver>
  <receiver android:name="com.onesignal.UpgradeReceiver" >
    <intent-filter>
      <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
  </receiver>
</application>

3.4. Replace all 3 of instances COM.YOUR.PACKAGE_NAME with your package name in AndroidManifest.xml.

4. Amazon API Key File

4.1 Place your api_key.txt in a folder named assets in the root of your project.

498

To create an api_key.txt for your app, follow our Generate an Amazon API Key guide.

4.2 Make sure to use the same keystore when building your APK as you did in step 2.4 in the Amazon Configuration guide.

Proguard

If you have Proguard enabled on your project, you must add the following line to your Proguard config file. The default filename is proguard-project.txt.

-dontwarn com.onesignal.**

-keep class com.google.android.gms.common.api.GoogleApiClient {
    void connect();
    void disconnect();
}

-keep public interface android.app.OnActivityPausedListener {*;}
-keep class com.onesignal.ActivityLifecycleListenerCompat** {*;}

-keep class com.onesignal.OSSubscriptionState {
    void changed(com.onesignal.OSPermissionState);
}

-keep class com.onesignal.OSPermissionChangedInternalObserver {
    void changed(com.onesignal.OSPermissionState);
}

-keep class com.onesignal.OSSubscriptionChangedInternalObserver {
    void changed(com.onesignal.OSSubscriptionState);
}

-keep class ** implements com.onesignal.OSPermissionObserver {
    void onOSPermissionChanged(com.onesignal.OSPermissionStateChanges);
}

-keep class ** implements com.onesignal.OSSubscriptionObserver {
    void onOSSubscriptionChanged(com.onesignal.OSSubscriptionStateChanges);
}

-keep class com.onesignal.shortcutbadger.impl.AdwHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.ApexHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.AsusHomeLauncher { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.DefaultBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.EverythingMeHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.HuaweiHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.LGHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.NewHtcHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.NovaHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.OPPOHomeBader { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.SamsungHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.SonyHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.VivoHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.XiaomiHomeBadger { <init>(...); }
-keep class com.onesignal.shortcutbadger.impl.ZukHomeBadger { <init>(...); }

-dontwarn com.amazon.**
-keep public class com.onesignal.ADMMessageHandler {*;}

Troubleshooting

If you run into any issues, please see our Android troubleshooting guide, or our general Troubleshooting section.


Testing

Normal Android devices do not support Amazon's ADM messaging, so you must test on an Amazon device. (First Generation Kindle Fire does not support push).


What’s Next