import org.joda.time.DateTime; //导入方法依赖的package包/类
private void showNotification(Game game) {
DateTime dateTime = new DateTime(game.getGameDateTime(), Constants.DATE.VEGAS_TIME_ZONE).plusSeconds(60);
if (dateTime.isAfterNow()) {
String ringtonePath = MultiProcessPreference.getDefaultSharedPreferences().getString(mContext.getString(R.string.key_notification_ringtone), null);
Uri soundUri;
if (ringtonePath == null) {
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
} else {
soundUri = Uri.parse(ringtonePath);
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.ic_league_white_24px)
.setContentTitle("Game Started - " + game.getLeagueType().getAcronym())
.setContentText(mContext.getString(R.string.team_vs_team_full, game.getFirstTeam().getCity(), game.getSecondTeam().getCity()))
.setSound(soundUri);
// Sets an ID for the notification
int mNotificationId = createHash(game.getFirstTeam().getCity() + game.getSecondTeam().getCity());
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
}