Android 在OneSignal推送通知上打开其他活动

Android 在OneSignal推送通知上打开其他活动,android,push-notification,onesignal,Android,Push Notification,Onesignal,我正在学习如何在Android设备上处理OneSignal推送通知。问题是,当应用程序关闭时,当我收到通知时,即使我定义了必要的函数(我猜),它仍然会打开“Splash活动”,它在清单中定义为主启动器。我需要打开一个包含有效负载数据的不同活动。我在创建这些代码时引用的链接是,我在上看到了该链接。我只是显示相关的代码,因为这个项目是保密的 这是我的清单文件 <application android:name="packageName.CustomAppName"

我正在学习如何在Android设备上处理OneSignal推送通知。问题是,当应用程序关闭时,当我收到通知时,即使我定义了必要的函数(我猜),它仍然会打开“Splash活动”,它在清单中定义为主启动器。我需要打开一个包含有效负载数据的不同活动。我在创建这些代码时引用的链接是,我在上看到了该链接。我只是显示相关的代码,因为这个项目是保密的

这是我的清单文件

<application
        android:name="packageName.CustomAppName"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT"
            android:value="DISABLED"/>
        <activity
            android:name="anotherPackageName.SplashActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="anotherPackageName.PaymentActivity"
            android:screenOrientation="portrait" />
        <service
            android:name="somepackagename.NotificationsForPayment"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE">
            <intent-filter>
                <action android:name="com.onesignal.NotificationExtender" />
            </intent-filter>
        </service>
</application>
这是我的客户通知开课

public class CustomNotificationOpening implements OneSignal.NotificationOpenedHandler {

    @Override
    public void notificationOpened(OSNotificationOpenResult notification) {
        notification.notification.payload.additionalData.names();
        JSONObject data = notification.notification.payload.additionalData;

        Intent intent = new Intent(CustomAppName.getInstance(), PaymentActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("paymentModel", data);
        CustomAppName.getInstance().startActivity(intent);
}
这是我的NotificationsForPayment类,它从NotificationExtender服务扩展而来

public class NotificationsForPayment extends NotificationExtenderService {
    @Override
    protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {
        NotificationExtenderService.OverrideSettings overrideSettings = new NotificationExtenderService.OverrideSettings();
        overrideSettings.extender = new NotificationCompat.Extender() {
            @Override
            public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
                // Sets the background notification color to Red on Android 5.0+ devices.
                Bitmap icon = BitmapFactory.decodeResource(CustomAppName.getInstance().getResources(),
                        R.drawable.ic_os_notification_fallback_white_24dp);
                builder.setLargeIcon(icon);
                return builder.setColor(new BigInteger("FF0000FF", 16).intValue());
            }
        };
    OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
}

我真的不知道我哪里做错了。当应用程序打开时,当我单击通知时,我可以看到“notificationOpened”函数正在启动。但当它关闭时,由于我无法调试程序,通知打开了启动活动,我知道该问这个问题了,因为我发现的答案都不起作用。在应用程序关闭时,是否有任何方法可以使用通知中的特定数据打开其他活动?非常感谢您的帮助。

找到了错误所在

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

该值应为“禁用”,而不是“禁用”

因此,更新的代码是:-

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


您的有效负载是什么样子的?只有“PaymentId”键下的字符串输入。但它是数据有效负载吗?通知?或者两者都有?这是“额外数据”,所以我假设数据有效载荷。只有一个成员具有“PaymentId”,其中包含一个值。
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT"
                android:value="DISABLE"/>