mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
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:
parent
f56b09980c
commit
adac3abcc6
1 changed files with 17 additions and 10 deletions
|
@ -55,6 +55,7 @@ public class Utils {
|
||||||
private static Boolean s_isFirstBootEver = null;
|
private static Boolean s_isFirstBootEver = null;
|
||||||
private static HashMap<String,String> s_phonesHash =
|
private static HashMap<String,String> s_phonesHash =
|
||||||
new HashMap<String,String>();
|
new HashMap<String,String>();
|
||||||
|
private static int s_nextCode = 0; // keep PendingIntents unique
|
||||||
|
|
||||||
private Utils() {}
|
private Utils() {}
|
||||||
|
|
||||||
|
@ -115,9 +116,15 @@ public class Utils {
|
||||||
public static void postNotification( Context context, Intent intent,
|
public static void postNotification( Context context, Intent intent,
|
||||||
int titleID, String body, int id )
|
int titleID, String body, int id )
|
||||||
{
|
{
|
||||||
PendingIntent pi = PendingIntent.
|
/* s_nextCode: per this link
|
||||||
getActivity( context, 0, intent,
|
http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT );
|
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 );
|
String title = context.getString( titleID );
|
||||||
Notification notification =
|
Notification notification =
|
||||||
|
@ -139,6 +146,13 @@ public class Utils {
|
||||||
nm.notify( id, notification );
|
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
|
// adapted from
|
||||||
// http://stackoverflow.com/questions/2174048/how-to-look-up-a-contacts-name-from-their-phone-number-on-android
|
// 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,
|
public static String phoneToContact( Context context, String phone,
|
||||||
|
@ -175,13 +189,6 @@ public class Utils {
|
||||||
return name;
|
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 )
|
public static View inflate( Context context, int layoutId )
|
||||||
{
|
{
|
||||||
LayoutInflater factory = LayoutInflater.from( context );
|
LayoutInflater factory = LayoutInflater.from( context );
|
||||||
|
|
Loading…
Add table
Reference in a new issue