当用户点击推送通知时,以下代码充当我的处理程序。该代码工作正常,并launchURL
准确记录在我的日志中。但是,作为下一步,我想将用户引导到一个名为ViewPushLink
. 我试图遵循 SO 上其他地方的类似说明,但作为新手,我将不胜感激一些具体的帮助。
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);
}
}
}
}
编辑:ExampleNotificationOpenedHandler
从我的主要活动中调用,如下所示:
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();