0

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.

cramopy
  • 3,459
  • 6
  • 28
  • 42
valerybodak
  • 4,195
  • 2
  • 42
  • 53

2 Answers2

1

First, If you return false, UA would launch the launcher Activity, in your case LoginActivity. Use return true;

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

Second, And You have created pendingIntent but it is not used. Refer Starting Activity from BroadcastReceiver for calling the activity from your BroadcastReceiver.

Community
  • 1
  • 1
Sowmia Sundararajan
  • 1,613
  • 2
  • 14
  • 17
0

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;
    }
}
ralepinski
  • 1,756
  • 8
  • 15