AUSTIN, Tex. — President Obama said Friday that law enforcement must be legally able to collect information from smartphones and other electronic devices, making clear, despite disagreement within his administration, that he opposes the stance on encryption taken by technology companies like Apple.

Speaking to an audience of about 2,100 technology executives and enthusiasts at the South by Southwest festival here, Mr. Obama delivered his most extensive comments on an issue that has split the technology community and pitted law enforcement against other national security agencies. Mr. Obama declined to comment specifically on the efforts by the F.B.I. to require Apple’s help in gaining data from an iPhone used by one of the terrorists in the December attack in San Bernardino, Calif.

But the president warned that America had already accepted that law enforcement can “rifle through your underwear” in searches for those suspected of preying on children, and he said there was no reason that a person’s digital information should be treated differently.

“If, technologically, it is possible to make an impenetrable device or system, where the encryption is so strong that there is no key, there is no door at all, then how do we apprehend the child pornographer?” Mr. Obama said. “How do we disrupt a terrorist plot?”