Skip to content

Instantly share code, notes, and snippets.

@jkasten2
Last active March 4, 2016 21:32
Show Gist options
  • Save jkasten2/f4548f1bddc9d740c8c9 to your computer and use it in GitHub Desktop.
Save jkasten2/f4548f1bddc9d740c8c9 to your computer and use it in GitHub Desktop.
package com.onesignal.example;
import android.app.Application;
import android.util.Log;
import com.onesignal.OneSignal;
import org.json.JSONObject
/***
TODO: Add the following line to your ANdroidManifest.xml in the application tag.
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
This is required so both your laucher Activity and the custom one below are not both launched.
***/
public class ExampleApplication extends Application {
private static Context appContext;
@Override
public void onCreate() {
super.onCreate();
appContext = this;
// Logging set to help debug issues, remove before releasing your app.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.WARN);
OneSignal.startInit(this)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
.setAutoPromptLocation(true)
.init();
}
private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
/**
* Callback to implement in your app to handle when a notification is opened from the Android status bar or
* a new one comes in while the app is running.
* This method is located in this Application class as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
*
* @param message The message string the user seen/should see in the Android status bar.
* @param additionalData The additionalData key value pair section you entered in on onesignal.com.
* @param isActive Was the app in the foreground when the notification was received.
*/
@Override
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
// TODO: Replace YourActivity with your Activity.
Intent intent = new Intent(ExampleApplication.appContext, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment