U.S. President Barack Obama said on Monday that NFL quarterback Colin Kaepernick was exercising his constitutional right by refusing to stand for the national anthem, although he added that the nature of the protest could make it hard for some to hear his message.

Kaepernick sparked controversy last month when he remained seated before a preseason game during the traditional rendition of "The Star-Spangled Banner," saying it was a protest against racial injustice and police brutality. During a second game last week, the San Francisco 49er took one knee instead of standing.

Many Americans have denounced the gesture as a sign of disrespect to the flag, though he has drawn support from some people, including some fellow players and Megan Rapinoe, a star of U.S. women's national soccer team.

Speaking in China after a gathering of leaders of 20 leading economies, Obama said he had no doubt about Kaepernick's sincerity but acknowledged that the protest was difficult for some members of the military and law enforcement to swallow.

"I think there are a lot of ways you can do it as a general matter when it comes to the flag and the national anthem and the meaning that that holds for our men and women in uniform and those who've fought for us. That is a tough thing for them to get past to then hear what his deeper concerns are," Obama said.

Kaepernick, who led San Francisco to the 2013 Super Bowl but has since been demoted to backup, is the latest professional athlete to use his celebrity to call attention to the issue of the mistreatment of minority groups by law enforcement. Over the past two years, a series of police killings of African-Americans in cities across the country have triggered protests and given rise to the Black Lives Matter movement.

Despite the controversy, Obama said he would rather have engaged young people "trying to think through how they can be part of our democratic process than people who are just sitting on the sidelines and not paying attention at all".

Obama, speaking at a news conference, said he had not been following the controversy closely, but added, "If nothing else what he's done is he's generated more conversation around some topics that need to be talked about."

"Sometimes it's messy, but it's the way democracy works."

In a gesture of solidarity with Kaepernick, Rapinoe knelt during the national anthem at a match on Sunday played by her professional team, the Seattle Reign, telling American Soccer Now that she was disgusted by the way Kaepernick has been treated in the media.

"Being a gay American, I know what it means to look at the flag and not have it protect all of your liberties," she added.

Although some American football fans have demanded that the National Football League punish Kaepernick, the NFL has issued a statement saying it encourages players to stand during the anthem but does not require them to do so. The 49ers have framed the issue in terms of all Americans' right of free expression.

The reaction on Twitter to Obama's comments was generally derisive, with many users questioning the president's patriotism.

"Just listen to his tone. I've never seen a more non-American POTUS in my lifetime," wrote Twitter user Wayne Allison, using the acronym of President of the United States.

But at least one Twitter user saw an underlying message to Obama's Chinese hosts in his emphasis on freedom of expression.

"Obama throwing shade at China using Colin Kaepernick. That's my president," wrote a user called The Black Gambit, using street jargon for a subtle criticism of a rival.