Fix bug 3509555 make notification always open right account
The problem was that: - Each account now has own new message notification - But PendingIntens for these all point to the same activity, only with different long extras (for acount IDs). - Framework merges these intents, because extras don't count as a "difference" in this case. - So when multiple new message notifications are shown, they'll all share the same intent internally, so they'll all open the same account. A quick workaround seems to be to set a unique URI to each intents. Bug 3509555 Change-Id: Ib02842bb32634cfdf01ae2d684dd04dfede23832
This commit is contained in:
parent
4408de227c
commit
dd6e6b8504
@ -39,6 +39,8 @@ import android.text.SpannableString;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.TextAppearanceSpan;
|
import android.text.style.TextAppearanceSpan;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that manages notifications.
|
* Class that manages notifications.
|
||||||
*
|
*
|
||||||
@ -97,6 +99,7 @@ public class NotificationController {
|
|||||||
// Pending Intent
|
// Pending Intent
|
||||||
PendingIntent pending = null;
|
PendingIntent pending = null;
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
|
intent = rewriteForPendingIntent(intent);
|
||||||
pending =
|
pending =
|
||||||
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
@ -198,6 +201,28 @@ public class NotificationController {
|
|||||||
return ContactStatusLoader.load(mContext, email).mPhoto;
|
return ContactStatusLoader.load(mContext, email).mPhoto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final AtomicInteger sSequenceNumber = new AtomicInteger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrite an intent so that it'll always look unique to {@link PendingIntent}.
|
||||||
|
*
|
||||||
|
* TODO This should be removed. Instead, use URIs which is unique to each account to open
|
||||||
|
* activities.
|
||||||
|
*/
|
||||||
|
private static Intent rewriteForPendingIntent(Intent original) {
|
||||||
|
if (original.getComponent() == null) {
|
||||||
|
return original; // Doesn't have a component set -- can't set a URI.
|
||||||
|
}
|
||||||
|
Uri.Builder builder = new Uri.Builder();
|
||||||
|
builder.scheme("content");
|
||||||
|
builder.authority("email-dummy");
|
||||||
|
builder.appendEncodedPath(Integer.toString(sSequenceNumber.incrementAndGet()));
|
||||||
|
|
||||||
|
// If a componentName is set, the data part won't be used to resolve an intent.
|
||||||
|
original.setData(builder.build());
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a notification
|
* Create a notification
|
||||||
*
|
*
|
||||||
@ -221,8 +246,8 @@ public class NotificationController {
|
|||||||
|
|
||||||
// Intent to open inbox
|
// Intent to open inbox
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
|
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
|
||||||
Welcome.createOpenAccountInboxIntent(mContext, accountId),
|
rewriteForPendingIntent(Welcome.createOpenAccountInboxIntent(mContext, accountId)),
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
0);
|
||||||
|
|
||||||
Notification.Builder builder = new Notification.Builder(mContext)
|
Notification.Builder builder = new Notification.Builder(mContext)
|
||||||
.setSmallIcon(R.drawable.stat_notify_email_generic)
|
.setSmallIcon(R.drawable.stat_notify_email_generic)
|
||||||
|
Loading…
Reference in New Issue
Block a user