fix bug where all notifications wound up launching the same game

because all their PendingIntents were the same by passing a unique
resultCode on creation.
This commit is contained in:
Eric House 2012-05-21 06:46:37 -07:00
parent f56b09980c
commit adac3abcc6

View file

@ -55,6 +55,7 @@ public class Utils {
private static Boolean s_isFirstBootEver = null;
private static HashMap<String,String> s_phonesHash =
new HashMap<String,String>();
private static int s_nextCode = 0; // keep PendingIntents unique
private Utils() {}
@ -115,9 +116,15 @@ public class Utils {
public static void postNotification( Context context, Intent intent,
int titleID, String body, int id )
{
PendingIntent pi = PendingIntent.
getActivity( context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT );
/* s_nextCode: per this link
http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager
one way to avoid getting the same PendingIntent for similar
Intents is to send a different second param each time,
though the docs say that param's ignored.
*/
PendingIntent pi =
PendingIntent.getActivity( context, ++s_nextCode, intent,
PendingIntent.FLAG_ONE_SHOT );
String title = context.getString( titleID );
Notification notification =
@ -139,6 +146,13 @@ public class Utils {
nm.notify( id, notification );
}
public static void cancelNotification( Context context, int id )
{
NotificationManager nm = (NotificationManager)
context.getSystemService( Context.NOTIFICATION_SERVICE );
nm.cancel( id );
}
// adapted from
// http://stackoverflow.com/questions/2174048/how-to-look-up-a-contacts-name-from-their-phone-number-on-android
public static String phoneToContact( Context context, String phone,
@ -175,13 +189,6 @@ public class Utils {
return name;
}
public static void cancelNotification( Context context, int id )
{
NotificationManager nm = (NotificationManager)
context.getSystemService( Context.NOTIFICATION_SERVICE );
nm.cancel( id );
}
public static View inflate( Context context, int layoutId )
{
LayoutInflater factory = LayoutInflater.from( context );