Ugandan academic and government critic Stella Nyanzi has been charged with a "cyber harassment" offence after she repeatedly posted criticism of President Yoweri Museveni and his wife on Facebook, according to court documents.

Nyanzi, a research fellow at Uganda's Makerere University, appeared in a court in the capital, Kampala, on Monday after being detained at a hotel on Friday shortly after hosting a fundraising drive to raise money for sanitary pads for schoolgirls.

"Dr Stella Nyanzi has been charged with cyber-harassment and offensive communication (and) using her Facebook posts to disturb President Museveni's privacy, which she denies," her lawyer Nicholas Opiyo told the AFP news agency.

"Dr Nyanzi is within her constitutional rights and we are for an all-out legal battle with the state to defend her rights."

She remains in custody pending a bail hearing.

Nyanzi's arrest and prosecution was an "indicator that those who express critical views of the Ugandan government, especially the first family, can face its wrath", said Maria Burnett, associate director for Africa at Human Rights Watch.

"The manner of Nyanzi's arrest on Friday was more about intimidation than law enforcement," she added.

Nyanzi is popular on Facebook for her relentless criticisms of Museveni, who has ruled since 1986.

Some Ugandan politicians have been recently saying they would back a proposal to remove the age limit from the country's constitution, the last obstacle to a possible life presidency for Museveni.

Museveni secured his latest term in office last year in a poll that independent monitors said lacked credibility and transparency.

Critics say he has placed relatives and loyalists in key government and military positions and wants his son, a major general in the army, to succeed him. They also increasingly warn that he plans to rule for life.

Anti-government protests are rarely permitted in Uganda and are often dispersed by police beatings, tear gas and the detention of activists.