当我点击Urban Airship的通知时,它会始终启动我的启动器活动(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类:
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;
}
可能是什么问题?提前谢谢。
答案 0 :(得分:1)
首先,如果您返回false,UA将启动启动器Activity,在您的情况下为LoginActivity。使用return true;
@Override
protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {
....
return true;
}
其次,您已创建了pendingIntent,但未使用它。 参考 Starting Activity from BroadcastReceiver 用于从BroadcastReceiver调用活动。
答案 1 :(得分:0)
行:
// Return false to let UA handle launching the launch activity
return false;
如果您返回true,它会通知Urban Airship SDK推送已处理,而不是自动启动启动器活动。
另外,我认为你想要的是以下内容:
@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;
}
}