城市飞艇。 PendingIntent 始终启动启动器 activity

Urban Airship. PendingIntent starts launcher activity always

当我点击来自 Urban Airship 的通知时,它总是启动我的启动器 activity (LoginActivity),但应该启动 AboutActivity。

<activity android:name=".activity.LoginActivity"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateVisible">

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

<activity android:name=".activity.AboutActivity"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:screenOrientation="portrait"/>

IntentReceiver class:

public class IntentReceiver extends BaseIntentReceiver {

private static final String TAG = "IntentReceiver";

@Override
protected void onChannelRegistrationSucceeded(Context context, String channelId) {
    Log.e(TAG, "Channel registration updated. Channel Id:" + channelId + ".");
}

@Override
protected void onChannelRegistrationFailed(Context context) {
    Log.e(TAG, "Channel registration failed.");
}

@Override
protected void onPushReceived(Context context, PushMessage message, int notificationId) {

}

@Override
protected void onBackgroundPushReceived(Context context, PushMessage message) {
    Log.e(TAG, "Received background push message: " + message);
}

@Override
protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {

    Bundle bundle = message.getPushBundle();
    if(bundle.containsKey("EEID") && bundle.containsKey("DATE") && bundle.containsKey("JOB")){

        Intent intent = new Intent(context, AboutActivity.class);
        intent.putExtra(Consts.EXTRA_EMPLOYEE_ID, bundle.getString("EEID"));
        intent.putExtra(Consts.EXTRA_DATE, bundle.getString("DATE"));
        intent.putExtra(Consts.EXTRA_JOB_ID, bundle.getString("JOB"));
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent.getActivity(context, 0, intent, 0);
    }

    // Return false to let UA handle launching the launch activity
    return false;
}

可能是什么问题?提前致谢。

首先,如果您 return 为 false,UA 将启动启动器 Activity,在您的情况下为 LoginActivity。使用 return true;

@Override
protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {
     ....
    return true;
}

其次,您创建了 pendingIntent 但未使用。 参考 Starting Activity from BroadcastReceiver 从您的 BroadcastReceiver 调用 activity。

行:

// Return false to let UA handle launching the launch activity
return false;

如果您 return 为真,它会通知 Urban Airship SDK 推送已处理,而不是自动启动启动器 activity。

另外,我想你想要的是:

@Override
protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {

    Bundle bundle = message.getPushBundle();
    if(bundle.containsKey("EEID") && bundle.containsKey("DATE") && bundle.containsKey("JOB")){
        Intent intent = new Intent(context, AboutActivity.class);
        intent.putExtra(Consts.EXTRA_EMPLOYEE_ID, bundle.getString("EEID"));
        intent.putExtra(Consts.EXTRA_DATE, bundle.getString("DATE"));
        intent.putExtra(Consts.EXTRA_JOB_ID, bundle.getString("JOB"));
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

        // Return true so Urban Airship does not auto start the activity
        return true;
    } else {
        return false;
    }
}