Sergeant Ivan Felton, of Mt Wellington police, said he prised the window open to get in, but the friend called police and he was arrested.
No one was hurt.
In court, defence lawyer Adam Holland said the accused and the young woman had been associated with each other for some time.
The defence team had intended to apply for bail, but decided not to after reviewing the file.
Mr Holland said they were seeking an address he could be bailed to outside of Auckland.
The accused applied for and was granted interim name suppression on the basis that his identification could potentially draw unwanted attention to the victim, and to allow time for his extended family to be notified of the allegations.
He was remanded in custody to appear again later this month.
One Tree Hill College principal Nick Coughlan did not know details of what had happened, but stressed the accused had not been a student at the school for a long time.
"Obviously this is a young man who needs some support," Mr Coughlan said.