OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Android Native SDK

OneSignal Android Native API Reference

📘

Just starting with Android?

Check out our Android SDK Setup guide.

ParameterData TypeDescription
Debugging
setLogLevelMethodEnable logging to help debug OneSignal implementation
Initialization
initBuilder MethodInitializes OneSignal to register the device for push notifications. Should be called in the onCreate method of your Application class. See Android SDK Setup for details and code examples.
startInitMethod
setInFocusDisplayingMethodSetting to control how OneSignal notifications will be shown when one is received while your app is in focus.
setNotificationOpenedHandlerBuilder Method
autoPromptLocationBuilder MethodAutomatically Prompt Users for Location
disableGmsMissingPromptBuilder MethodAutomatically Prompt User to update Google Play if out of date
unsubscribeWhenNotificationsAreDisabledBuilder MethodIf notifications are disabled for your app unsubscribe them from OneSignal.
filterOtherGCMReceiversBuilder MethodEnable to prevent other broadcast receivers from receiving OneSignal FCM / GCM payloads.
Handling Notifications
NotificationReceivedHandlerHandlerWhen a notification is received by a device
NotificationOpenedHandlerHandlerWhen a user takes an action on a notification
Opened ActionAndroid ManifestDisable resuming launcher activity when notification is opened
Privacy
setRequiresUserPrivacyConsentMethodDelays initialization of the SDK until the user provides privacy consent
consentGrantedMethodTells the SDK that the user has provided privacy consent (if required)
User StatusMore Details
getPermissionSubscriptionStateMethodGet the current notification and permission state. Returns a OSPermissionSubscriptionState type.
addPermissionObserverMethodObserver method for Current Device Record's Permission status changes.
addSubscriptionObserverMethodObserver method for Current Device Record's Subscription status changes.
setSubscriptionMethodDisable OneSignal from sending notifications to current device.
External IDs
setExternalUserIdMethodAllows you to use your own system's user ID's to send push notifications to your users. To tie a user to a given user ID, you can use this method.
removeExternalUserIdMethodRemoves whatever was set as the current user's external user ID.
Tagging
getTagsMethodView Tags from current device record.
sendTagMethodAdd a single Data Tag to current device record.
sendTagsMethodAdd multiple Data Tags to current device record.
deleteTagMethodDelete a Tag from current device record.
deleteTagsMethodDelete multiple Tags from current device record.
Location Data
setLocationSharedMethodDisable or Enable SDK location collection. See Handling Personal Data.
promptLocationMethodPrompt Users for Location Not Recommended

Recommended: Use In-App Message Location Opt-In Prompt.
Sending Notifications
postNotificationMethodSend or schedule a notification to a OneSignal Player ID.
cancelNotificationMethodDelete a single app notification
clearOneSignalNotificationsMethodDelete all app notifications
In-App Messaging
addTriggerMethodAdd a trigger, may show an In-App Message if its triggers conditions were met.
addTriggersMethodAdd a map of triggers, may show an In-App Message if its triggers conditions were met.
removeTriggerForKeyMethodRemoves a list of triggers based on a collection of keys, may show an In-App Message if its triggers conditions were met.
getTriggerValueForKeyMethodGets a trigger value for a provided trigger key.
pauseInAppMessagesMethodAllows you to temporarily pause all In App Messages.
setInAppMessageClickHandlerHandlerSets an In App Message opened block
Email
setEmailMethodSet user's email. Creates a new user record for the email address. Use sendTag if you want to update a push user record with the email.
logoutEmailMethodLog user out to dissociate email from device
addEmailSubscriptionObserverMethodObserver for subscription changes to email
Objects
OSNotificationOpenResultObjectInformation returned from a notification the user received
OSNotificationObjectNotification the user received
OSNotificationActionAction the user took on the notification
OSNotificationPayloadContents and settings of the notification the user received
Appearance
enableVibrateMethodWhen user receives notification, vibrate device less
enableSoundMethodWhen user receives notification, do not play a sound

Initialization

startInit

Method

Initializes OneSignal to register the device for push notifications. Should be call in the onCreate of your Application class.

ParameterTypeDescription
contextContextYour Application context.

Returns

OneSignal.Builder - See below for a list of methods available.

public class YourAppClass extends Application {
   @Override
   public void onCreate() {
      super.onCreate();
      OneSignal.startInit(this).init();
   }
}

autoPromptLocation

Builder Method

Prompts the user for location permissions. This allows for geotagging so you can send notifications to users based on location. See promptLocation for more details.

ParameterTypeDescription
promptboolean

false (Default) - do not prompt


true - prompt users for location permissions when your app starts.

OneSignal.startInit(this)
  .autoPromptLocation(true)
  .init();

setNotificationReceivedHandler

Builder Method

Sets a notification received handler that will fire when a notification is received. It will be fired when your app is in focus or in the background.

ParameterTypeDescription
handlerNotificationReceivedHandlerInstance to a class implementing this interference.
OneSignal.startInit(this)   
   .setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
   .init();

See the NotificationReceivedHandler documentation for an example of the ExampleNotificationReceivedHandler class.

setNotificationOpenedHandler

Builder Method

Sets a notification opened handler. The instance will be called when a notification is tapped on from the notification shade or when closing an Alert notification shown in the app.

ParameterTypeDescription
handlerNotificationOpenedHandlerInstance to a class implementing this interference.
OneSignal.startInit(this)   
   .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
   .init();

See the NotificationOpenedHandler documentation for an example of the ExampleNotificationOpenedHandler class.

disableGmsMissingPrompt

Builder Method

Prompts the user to update/enable Google Play services if it's disabled on the device.

ParameterTypeDescription
promptboolean

false (Default) - prompt users



true to never show the out of date prompt.

OneSignal.startInit(this)
  .disableGmsMissingPrompt(true)
  .init();

unsubscribeWhenNotificationsAreDisabled

Builder Method

Android Devices can still get Data/Silent Notifications even if the user unsubscribes from the App Settings. This will happen when your users go to Settings > Apps and turn off notifications or if they long press one of your notifications and select "block notifications".

If notifications are disabled for your app, setting this method to true will unsubscribe the user from OneSignal and re-subscribe them if they turn notifications back on.

This is false by default, so Android users will be marked as subscribed in this case and can receive data/silent notifications. They will not see any data or get alerted if they unsubscribed from the App Settings.

ParameterTypeDescription
promptboolean

false (Default) - don't unsubscribe users



true - unsubscribe users when notifications are disabled

OneSignal.startInit(this)
  .unsubscribeWhenNotificationsAreDisabled(true)
  .init();

filterOtherGCMReceivers

Builder Method

Prevents other broadcast receivers from receiving OneSignal FCM/GCM payloads i.e. stops other libraries that implement notifications from throwing exceptions or showing double notifications when a OneSignal Notification is received.

Other non-OneSignal payloads will still be passed through so your app can handle FCM / GCM payloads from other back-ends. Note however you can't use multiple Google Project numbers / Sender IDs. They must be the same if you are using multiple providers, otherwise there will be unexpected unsubscribes.

OneSignal.startInit(this)
  .filterOtherGCMReceivers(true)
  .init();

Status methods

The following methods provide details on the permission and subscribed state of the device. Use getPermissionSubscriptionState to get the current immediate state and use addPermissionObserver and / or addSubscriptionObserver to react to changes.

Status Recommendations

getPermissionSubscriptionState - Use to load your UI to the correct state. Such as showing a toggle button to enable notifications.

addSubscriptionObserver - Use to update your server when the user becomes subscribed or unsubscribed and to get the OneSignal player / user id.
Example if you need to store the OneSignal player / user id on your backend you can make a REST API call directly from the observer's callback. The OneSignal observer ONLY fires when there is a change, including NOT firing even if the app has been restarted. This helps ensure your not making unnecessary network calls to your backend on each app restart if nothing changed.

getPermissionSubscriptionState

Method

Get the current notification and permission state. Returns a OSPermissionSubscriptionState type described below.

MethodTypeDescription
getPermissionStatus()OSPermissionStateAndroid Notification Permissions state
getSubscriptionStatus()OSSubscriptionStateGoogle and OneSignal subscription state
OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();
status.getPermissionStatus().getEnabled();
    
status.getSubscriptionStatus().getSubscribed();
status.getSubscriptionStatus().getUserSubscriptionSetting();
status.getSubscriptionStatus().getUserId();
status.getSubscriptionStatus().getPushToken();

OSPermissionState

Class

The Notification permission status of your app. Contains enabled value to know if the user has turned off notifications for your app.

MethodTypeDescription
getEnabled()booleantrue if notifications are enabled.
Will only be false if the user disables notifications for your app from the system settings

OSSubscriptionState

Class

Provides subscription state details of subscribed to push as well as the OneSignal player / user id and the devices push token.

MethodTypeDescription
getSubscribed()booleantrue if the device can receive push notifications from OneSignal.
false if the device has disabled push notifications or not successfully registered yet with either OneSignal or FCM with a valid push token.
getUserSubscriptionSetting()booleanWill be true unless you have called setSubscription with false.
getUserId()StringThe OneSignal player / user id for the device.
null if the device hasn't registered with OneSignal's server yet.
getPushToken()StringThe GCM / FCM push token for the device.
null if the device hasn't registered with Google's server yet.

addPermissionObserver

Handler

The onOSPermissionChanged method will be fired on the passed-in object when a notification permission setting changes. This happens when the user enables or disables notifications for your app from the system settings outside of your app. Disable detection is supported on Android 4.4+.

public class MainActivity extends Activity implements OSPermissionObserver {
  protected void onCreate(Bundle savedInstanceState) {
    OneSignal.addPermissionObserver(this);
  }
  
  public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) {
    if (stateChanges.getFrom().getEnabled() &&
        !stateChanges.getTo().getEnabled()) {
         new AlertDialog.Builder(this)
             .setMessage("Notifications Disabled!")
             .show();
      }
   
      Log.i("Debug", "onOSPermissionChanged: " + stateChanges);
  }
}

// Example Logcat entry - User disabling notifications then returning to your app.
// onOSPermissionChanged{"from":{"enabled":true},"to":{"enabled":false}}

🚧

Keep a Reference

Make sure to hold a reference to your observable at the class level, otherwise it my not fire.

👍

Leak Safe

OneSignal holds a weak reference to your observer so it's guaranteed not to leak your Activity.

OSPermissionStateChanges

Class

Instance is given to your onOSPermissionChanged method which provides what the value was ("from") and what the value is now ("to").

MethodTypeDescription
getFrom()OSSubscriptionStateWhat the state was
getTo()OSSubscriptionStateWhat the state is now

addSubscriptionObserver

Method

The onOSSubscriptionChanged method will be fired on the passed-in object when a notification subscription property changes.

This includes the following events:

  • Getting a Registration Id (push token) from Google
  • Getting a player / user id from OneSignal
  • OneSignal.setSubscription is called
  • User disables or enables notifications
public class MainActivity extends Activity implements OSSubscriptionObserver {
  protected void onCreate(Bundle savedInstanceState) {
    OneSignal.addSubscriptionObserver(this);
  }
  
  public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
    if (!stateChanges.getFrom().getSubscribed() &&
        stateChanges.getTo().getSubscribed()) {
         new AlertDialog.Builder(this)
             .setMessage("You've successfully subscribed to push notifications!")
             .show();
        // get player ID
        stateChanges.getTo().getUserId();
      }
   
      Log.i("Debug", "onOSPermissionChanged: " + stateChanges);
  }
}

/*
Example Logcat entry - User disabling notifications then returning to your app.
onOSSubscriptionChanged:
{"from":{"pushToken":"APA91bG9cmZ262s5gJhr8jvbg1q7aiviEC6lcOCgAQliEzHKO3eOdX5cm7IQqMSWfy8Od7Ol3jSjFfvCfeO2UYUpanJCURJ8RdhgEuV8grYxOCwPNJr5GoqcWTQOaL9u-qE2PQcFlv4K","userSubscriptionSetting":true,"subscribed":false},
 "to":  {"userId":"22712a53-9b5c-4eab-a828-f18f81167fef","pushToken":"APA91bG9cmZ262s5gJhr8jvbg1q7aiviEC6lcOCgAQliEzHKO3eOdX5cm7IQqMSWfy8Od7Ol3jSjFfvCfeO2UYUpanJCURJ8RdhgEuV8grYxOCwPNJr5GoqcWTQOaL9u-qE2PQcFlv4K","userSubscriptionSetting":true,"subscribed":true}}

🚧

Keep a Reference

Make sure to hold a reference to your observable at the class level, otherwise it my not fire.

👍

Leak Safe

OneSignal holds a weak reference to your observer so it's guaranteed not to leak your Activity.

OSSubscriptionStateChanges

Class

Instance is given to your onOSSubscriptionChanged method which provides what the value was ("from") and what the value is now ("to").

MethodTypeDescription
getFrom()OSPermissionStateWhat the state was (past)
getTo()OSPermissionStateWhat the state is now

Sending Notifications

postNotification

Method

Allows you to send notifications from user to user or schedule ones in the future to be delivered to the current device.

ParameterTypeDescription
parametersJSONObjectContains notification options, see Create Notification POST call for all options.

postNotificationResponseHandler

Fires delegate when the notification was created or fails to be created.

ResponseMethod
Successvoid onSuccess(JSONObject response)
Failurevoid onFailure(JSONObject response)
try {
  OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + userId + "']}"), null);
} catch (JSONException e) {
  e.printStackTrace();
}
try {
  OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + "userId" + "']}"),
     new OneSignal.PostNotificationResponseHandler() {
       @Override
       public void onSuccess(JSONObject response) {
         Log.i("OneSignalExample", "postNotification Success: " + response.toString());
       }

       @Override
       public void onFailure(JSONObject response) {
         Log.e("OneSignalExample", "postNotification Failure: " + response.toString());
       }
     });
} catch (JSONException e) {
  e.printStackTrace();
}

See the Create Notification REST API POST call for a list of all possible options. Note: You can only use include_player_ids as a targeting parameter from your app. Other target options such as tags and included_segments require your OneSignal App REST API key which can only be used from your server.

cancelNotification

Method

Cancels a single OneSignal notification based on its Android notification integer id. Use instead of Android's NotificationManager.cancel(id); otherwise the notification will be restored when your app is restarted.

int id = 1234;
OneSignal.cancelNotification(id);

clearOneSignalNotifications

Method

Removes all OneSignal notifications from the Notification Shade. If you just use NotificationManager.cancelAll(); OneSignal notifications will be restored your app is restarted.

OneSignal.clearOneSignalNotifications();

Receiving Notifications

NotificationReceivedHandler

Handler

Fires when a notification is received. It will be fired when your app is in focus or in the background.

ParameterTypeDescription
notificationOSNotificationContains both the user's response and properties of the notification.
class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
  @Override
  public void notificationReceived(OSNotification notification) {
    JSONObject data = notification.payload.additionalData;
    String customKey;

    if (data != null) {
      customKey = data.optString("customkey", null);
      if (customKey != null)
        Log.i("OneSignalExample", "customkey set with value: " + customKey);
    }
  }
}

NotificationOpenedHandler

Handler

Use to process a OneSignal notification the user just tapped on.

ParameterTypeDescription
resultOSNotificationOpenResultContains both the user's response and properties of the notification.
class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
  // This fires when a notification is opened by tapping on it.
  @Override
  public void notificationOpened(OSNotificationOpenResult result) {
    OSNotificationAction.ActionType actionType = result.action.type;
    JSONObject data = result.notification.payload.additionalData;
    String customKey;
    
    Log.i("OSNotificationPayload", "result.notification.payload.toJSONObject().toString(): " + result.notification.payload.toJSONObject().toString());


    if (data != null) {
      customKey = data.optString("customkey", null);
      if (customKey != null)
        Log.i("OneSignalExample", "customkey set with value: " + customKey);
    }

    if (actionType == OSNotificationAction.ActionType.ActionTaken)
      Log.i("OneSignalExample", "Button pressed with id: " + result.action.actionID);

    // The following can be used to open an Activity of your choice.
    // Replace - getApplicationContext() - with any Android Context.
    // Intent intent = new Intent(getApplicationContext(), YourActivity.class);
    // intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    // startActivity(intent);

     // Add the following to your AndroidManifest.xml to prevent the launching of your main Activity
     //   if you are calling startActivity above.
     /* 
        <application ...>
          <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
        </application>
     */
  }
}
//result.notification.payload.toJSONObject().toString(): 
{ 
   "notificationID":"1fe89041-c33b-4bd6-87ad-fdf51157664a",
   "title":"Notification Title",
   "body":"Message of the notification",
   "additionalData":{ 
      "additional_data_key_1":"data_value_1",
      "data_key_2":"data_value_2"
   },
   "smallIcon":"small_icon_resource_name",
   "largeIcon":"https:\/\/img.onesignal.com\/n\/267522bc-e992-48d9-ad13-17d8f3336ae5.png",
   "bigPicture":"https:\/\/img.onesignal.com\/n\/65c5cba1-1bbd-49c4-9b26-ed7036a081f4.jpg",
   "smallIconAccentColor":"FF900FF",
   "launchURL":"https:\/\/onesignal.com\/launch-url",
   "lockScreenVisibility":1,
   "groupKey":"Group_key_23",
   "groupMessage":"Group_message",
   "actionButtons":[ 
      { 
         "id":"action_id",
         "text":"Shown_Text",
         "icon":"Icon_url"
      },
      { 
         "id":"action_id_2",
         "text":"Shown_text_2",
         "icon":"icon_url_2"
      }
   ],
   "fromProjectNumber":"388536902528",
   "collapseId":"collapse_id_1",
   "priority":6,
   "rawPayload":"{\"google.delivered_priority\":\"high\",\"google.sent_time\":1568060314614,\"google.ttl\":280000,\"google.original_priority\":\"high\",\"custom\":\"{\\\"a\\\":{\\\"additional_data_key_1\\\":\\\"data_value_1\\\",\\\"data_key_2\\\":\\\"data_value_2\\\",\\\"actionButtons\\\":[{\\\"id\\\":\\\"action_id\\\",\\\"text\\\":\\\"Shown_Text\\\",\\\"icon\\\":\\\"Icon_url\\\"},{\\\"id\\\":\\\"action_id_2\\\",\\\"text\\\":\\\"Shown_text_2\\\",\\\"icon\\\":\\\"icon_url_2\\\"}],\\\"actionSelected\\\":\\\"__DEFAULT__\\\"},\\\"u\\\":\\\"https:\\\\\\\/\\\\\\\/onesignal.com\\\\\\\/launch-url\\\",\\\"i\\\":\\\"1fe89041-c33b-4bd6-87ad-fdf51157664a\\\"}\",\"oth_chnl\":\"\",\"bgn\":\"1\",\"grp\":\"Group_key_23\",\"pri\":\"6\",\"vis\":\"1\",\"bgac\":\"FF900FF\",\"chnl\":\"{\\\"dscr\\\":\\\"test\\\",\\\"grp_nm\\\":\\\"test\\\",\\\"grp_id\\\":\\\"OS_1249f7c6-cb84-4685-8ba3-1a99b690ccdb\\\",\\\"id\\\":\\\"OS_fb1d04a7-dc4d-4d77-8b0a-8fb48ea2460b\\\",\\\"nm\\\":\\\"High Importance, default sound and vibration\\\"}\",\"from\":\"388536902528\",\"alert\":\"Message of the notification\",\"bicon\":\"https:\\\/\\\/img.onesignal.com\\\/n\\\/65c5cba1-1bbd-49c4-9b26-ed7036a081f4.jpg\",\"licon\":\"https:\\\/\\\/img.onesignal.com\\\/n\\\/267522bc-e992-48d9-ad13-17d8f3336ae5.png\",\"sicon\":\"small_icon_resource_name\",\"title\":\"Notification Title\",\"grp_msg\":\"Group_message\",\"google.message_id\":\"0:1568060314683605%616610dd87cd175f\",\"collapse_key\":\"collapse_id_1\",\"notificationId\":2143835591}"
}

OSNotificationOpenResult

Class

The information returned from a notification the user received.

ParameterTypeDescription
notificationOSNotificationNotification the user received.
actionOSNotificationActionThe action the user took on the notification.

OSNotification

Class

The notification the user received.

ParameterTypeDescription
isAppInFocusbooleanWas app in focus.
shownbooleanWas notification shown to the user. Will be false for silent notifications.
androidNotificationIdintAndroid Notification assigned to the notification. Can be used to cancel or replace the notification.
payloadOSNotificationPayloadPayload received from OneSignal.
displayTypeDisplayTypeHow the notification was displayed to the user. Can be set to Notification, InAppAlert, or None if it was not displayed.
groupedNotificationsList<OSNotificationPayload>Notification is a summary notification for a group this will contain all notification payloads it was created from.

DisplayType

How the notification was displayed to the user. Part of OSNotification. See [inFocusDisplaying](https://documentation.onesignal.com/docs/sdk-reference#app-in-focus-notification-display for more information on how this is used.

Notification - native notification display.
InAppAlert (Default) - native alert dialog display (note this is not an In-App Message).
None - notification is silent, or inFocusDisplaying is disabled.

OSNotificationAction

Class

The action the user took on the notification.

ParameterTypeDescription
typeActionTypeWas the notification opened normally (Opened) or was a button pressed on the notification (ActionTaken).
actionIDStringIf type == ActionTaken then this will contain the id of the button pressed.

OSNotificationPayload

Class

Contents and settings of the notification the user received.

ParameterTypeDescription
notificationIDStringOneSignal notification UUID.
titleStringTitle of the notification.
bodyStringBody of the notification.
additionalDataJSONObjectCustom additional data that was sent with the notification. Set on the dashboard under Options > Additional Data or with the 'data' field on the REST API.
smallIconStringSmall icon resource name set on the notification.
largeIconStringLarge icon set on the notification.
bigPictureStringBig picture image set on the notification.
smallIconAccentColorStringAccent color shown around small notification icon on Android 5+ devices. ARGB format.
launchUrlStringURL to open when opening the notification.
soundStringSound resource to play when the notification is shown. Read more here
ledColorStringDevices that have a notification LED will blink in this color. ARGB format.
lockScreenVisibilityintPrivacy setting for how the notification should be shown on the lockscreen of Android 5+ devices.

1 (Default) - Public (fully visible)
0 - Private (Contents are hidden)
-1 - Secret (not shown).
groupKeyStringNotifications with this same key will be grouped together as a single summary notification.
groupMessagestringSummary text displayed in the summary notification.
actionButtonsList<ActionButton>List of action buttons on the notification.
fromProjectNumberStringThe Google project number the notification was sent under.
backgroundImageLayoutBackgroundImageLayoutIf a background image was set this object will be available.
rawPayloadStringRaw JSON payload string received from OneSignal.

ActionButton

Object

List of action buttons on the notification. Part of OSNotificationPayload.

ParameterTypeDescription
idStringId assigned to the button.
textStringText show on the button to the user.
iconStringIcon shown on the button.

BackgroundImageLayout

Object

If a background image was set, this object will be available. Part of OSNotificationPayload.

ParameterTypeDescription
imageStringImage URL or name used as the background image.
titleTextColorStringText color of the title on the notification. ARGB Format.
bodyTextColorStringText color of the body on the notification. ARGB Format.

Opened Action

Android Manifest

By default OneSignal will open or resume your launcher Activity when a notification is tapped on. You can disable this behavior by adding the meta-data tag com.onesignal.NotificationOpened.DEFAULT set to DISABLE inside your application tag in your AndroidManifest.xml.

<application ...>
   <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>

Make sure you are initializing OneSignal with setNotificationOpenedHandler in the onCreate method in your Application class. You will need to call startActivity from this callback.


Appearance

enableVibrate

Method

By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode. Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.

You can link this action to a UI button to give your user a vibration option for your notifications.

OneSignal.enableVibrate(false);

enableSound

Method

By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on. Passing false means that the device will only vibrate unless the device is set to a total silent mode.

You can link this action to a UI button to give your user a different sound option for your notifications.

OneSignal.enableSound(false);

Updated 14 days ago



Android Native SDK


OneSignal Android Native API Reference

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.