我的通知点击有一个奇怪的问题。以下是我创建通知的方式:
Intent contentIntent;
if (appointmentId == null) {
// not an appointment message
contentIntent = ConversationDetailsActivity.getLaunchIntent(this, conversationId);
} else {
// appointment message
contentIntent = AppointmentDetailsActivity.getLaunchIntent(this, appointmentId);
}
PendingIntent contentPendingIntent = PendingIntent.getActivity(this, conversationId.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_bubble_24dp)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(getString(R.string.notification_title))
.setContentText(message)
.setContentIntent(contentPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[]{0, 1000, 1000, 1000, 1000})
.setLights(Color.WHITE, 3000, 3000);
manager.notify(conversationId.hashCode(), builder.build());
当我收到'appointmentId'时,通知点击实际启动了AppointmentDetailsActivity。当appointmentId为null时,它应该启动ConversationDetailsActivity,但它会启动MainActivity。我尝试了android:exported="true"
解决方案,但它没有用。
两个活动的'getLaunchIntent'方法是相同的,清单声明也是相同的。通知是从服务创建的。我很困惑。请帮我启动正确的活动。谢谢。
AppointmentDetailsActivity的getLaunchIntent(有效的):
public static Intent getLaunchIntent(final Context context, final String appointmentId) {
Intent intent = new Intent(context, AppointmentDetailsActivity.class);
intent.putExtra("appointmentId", appointmentId);
return intent;
}
ConversationDetailsActivity的getLaunchIntent方法(不起作用的方法):
public static Intent getLaunchIntent(final Context context, final String conversationId) {
Intent intent = new Intent(context, ConversationDetailsActivity.class);
intent.putExtra("conversationId", conversationId);
return intent;
}
并显示声明:
<activity
android:name=".ui.conversations.ConversationDetailsActivity"
android:windowSoftInputMode="stateHidden"
/>
<activity android:name=".ui.appointments.AppointmentDetailsActivity"/>
这个答案here解决了这个问题。