Sure, and it's really the only way you can do it. You can't do anything in init because that's called once before anyone even hits the site.
If you want to minimize the processing, you could analyze the User-Agent
string once and store the result in the session.