Can we detect in Apex or Visualforce whether the page is being opened in on a Phone or a Tablet device?

I'm looking to render VF page conditionally if it is viewed on Tablet or if it is viewed on a Phone.

  • 1
    possible duplicate of Detect if Visualforce Page is in Salesforce1 – greenstork Sep 9 '14 at 19:26
  • hmmm.. I don't think so, I know we can detect if page is in SF1 as we can but wanted some solid in roads for an answer to see if we can detect if it is an iPad or an iPhone ... – VarunC Sep 9 '14 at 19:36
  • 2
    Check the User-Agent into your apex page header Apexpages.currentPage().getHeaders().get('User-Agent'). I'm not too sure, but you can find a lot of info in there. – Cloud Ninja Sep 9 '14 at 22:45

We can do it by getting the user-agent: Server End

String userAgent = System.currentPageReference().getHeaders().get('User-Agent');

if (userAgent.contains('iPhone')){
           // your code here
}
else if (userAgent.contains('iPad')){
         // your code here
}  //added comment to allow code formatting
  • Sure, if you're 100% certain that all your users are on Apple devices... – Mads Mogenshøj Mar 26 '15 at 15:26

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.