After several years, the police force found out and told him he could not run a private website that was earning money from advertisements while serving as a police officer.
Ma chose his website, a move that later proved fruitful. His Danlan.org has spawned a Chinese-language dating app for men called Blued that has garnered 15 million users, 3 million of them outside China, over two years.
And last month, his company, Blue City, received $30 million in funding from Silicon Valley venture capital company DCM Ventures. Ma hopes to use the money to expand abroad and possibly prepare for an IPO. He is also considering launching a dating app for lesbians.
In a country where the government considers any activism dangerous and where homosexuality has traditionally been taboo, Ma has managed to build his business partly by reaching out to government agencies and showing them he can provide a public service in spreading safe-sex messages.
In 2012, he was invited to meet with now-Premier Li Keqiang because of his AIDS prevention work.
Wu Zunyou, director of the Chinese Center for Disease Control and Prevention's AIDS and sexually transmitted diseases centre, praised the app for its usefulness in conveying information to the lesbian, gay, bisexual and transgender, or LGBT, community.
"It's very hard to receive so many registered users in such a short time," Wu told The Associated Press last week at an AIDS awareness event held by Blue City and also attended by local government officials. "None of our public awareness websites can receive such attention. This is a very important channel to be able to spread information about AIDS prevention among the LGBT community."
The app allows users to look for people by location or the last time they logged on. It also enables group settings so people can organize activities such as hiking or assembling a basketball team, as well as providing information from health authorities on locations for HIV testing and treatment.
Andrea Pastorelli, a policy specialist at the United Nations Development Programme, said the Chinese CDC had recognized the app's usefulness in reaching people they were unable to.
"They are having a real issue reaching out to the most marginalized people and in China that's where the epidemic is," he said.
"The fact that they have been able to attract this much money shows that there is interest in the so-called pink market," Pastorelli added. "Private companies are realizing that gay people exist and gay people represent a huge market."
An investment manager at the Beijing office of DCM Ventures who asked not to be named because she was not authorized to speak to the media confirmed that the company had invested $30 million in Blue City, saying its future outlook was promising.
"Five per cent of the total population are LGBT people," she said. "Social attitudes toward gay people will become more and more tolerant in the future."
For Ma, 37, who goes by the online pseudonym Geng Le, the investment signals a shift in attitudes already among Chinese toward homosexuals.
Five years ago, his website Danlan.org would be regularly shut down. Today, that doesn't happen anymore, and it carries discussions on whether to legalize same-sex marriage, for example.
"I now feel more and more comfortable saying, 'Yes, I'm gay and yes, what I do is run a gay-themed website,'" he said.
Still, the app does provide privacy for people who are worried about others finding out about their sexual orientation by allowing them to use their smartphone to meet someone, he said.
A law against "hooliganism" that had been used to target gays was eliminated in 1997 and homosexuality was declassified as a mental disorder in 2001, but some clinics still promise to "cure" people by offering conversion therapy that includes electric shocks. China does not recognize same-sex partnerships and no laws outlaw discrimination against homosexuals.
However, more organizations are being created in China that are specifically devoted to LGBT advocacy issues, and gay bars that once could only be found in bigger cities like Beijing and Shanghai are increasingly opening up in smaller cities.
Ma quit his job as deputy director of a division of the Qinhuangdao police force in March 2012. He still misses being a police officer, his dream job since childhood. He says some former colleagues cannot accept what he is doing because they think homosexuality is "abnormal." Ma says he hopes to change their thinking.
Blue City employs about 40 software engineers, designers, salespeople and advocates.
"I would like to use the power of the economy to promote the LGBT community," he said. "In many ways, the economy can trigger changes in policies. So if, for example, I do this thing very well, if my users go from 15 million to many more in the future, if we can go public, I can tell the government: See, we can go public being a 'gay company' and we haven't caused you any trouble."