当用户点击推送通知时,以下代码将作为我的处理程序。该代码正常工作,并且@GlideModule
public class QNGlideModule extends AppGlideModule {
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
已准确记录在我的日志中。但是,下一步,我想将用户引导到名为launchURL
的活动。我尝试遵循在S.O.上其他地方找到的类似说明,但是作为一个新手,我将不胜感激。
ViewPushLink
编辑: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
答案 0 :(得分:0)
将您的活动更改为此;当然可以,对您有帮助。
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);
Intent intent = new Intent(getApplicationContext, ViewPushLink.class)
startActivity(intent);
}
}
}
}
答案 1 :(得分:0)
将代码放入项目的应用程序类中。
对于使用OneSignal SDK进行推送通知处理,需要考虑三件事。{如果您的项目有多个片段,并且一个Main Activity(Navigation Drawer Activity),其余的其他活动则从MainActivity的片段中调用}
示例:
public XYZApplication extends Application{
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) {
String target = data.optString("target");
String action = "";
switch (target) {
case "xyz":
action = data.optString("action");
Utils.setTarget(target);
if (action.equalsIgnoreCase("xyz")
|| action.equalsIgnoreCase("abc")) {
Intent xyzIntent = new Intent(getApplicationContext(), XYZActivity.class);
homeIntent.putExtra("action_key", "action_xyz");
homeIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(xyzIntent);
}
有关更多详细信息,请参阅一个信号SDK文档 https://documentation.onesignal.com/docs