Search code examples
androidurbanairship.com

Urban Airship. PendingIntent starts launcher activity always


When I click on notification from Urban Airship it starts my launcher activity (LoginActivity) always, but should starts 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;
}

What could be the problem? Thanks in advance.


Solution

  • The lines:

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

    If you return true, it notifies the Urban Airship SDK that the push was handled and NOT to auto launch the launcher activity.

    Also, I think what you are wanting is the following:

    @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;
        }
    }