The following code serves as my handler when the user taps a push notification. The code is working properly and launchURL
is accurately recorded in my log. However, as a next step I would like to direct the user to an activity called ViewPushLink
. I have attempted to follow similar instructions found elsewhere on S.O., but as a newbie, I would appreciate some specific help.
class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
public static String launchURL;
@Override
public void notificationOpened(OSNotificationOpenResult result) {
OSNotificationAction.ActionType actionType = result.action.type;
JSONObject data = result.notification.payload.additionalData;
if (data != null) {
launchURL = data.optString("launchURL");
if (launchURL != null) {
Log.i("OneSignalExample", "launchURL value: " + launchURL);
}
}
}
}
EDIT: ExampleNotificationOpenedHandler
is called from my Main Activity as show below:
public class MainActivity extends AppCompatActivity {
private ProgressDialog progress;
public static boolean isNetworkStatusAvailable (Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null)
{
NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
if(netInfos != null)
if(netInfos.isConnected())
return true;
}
return false;
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// OneSignal Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
.init();