If you can make due with JavaScript checking you can use the method outlined in this documentation that looks for the sforce JavaScript object, and just adapt it to do your work.
if( (typeof sforce != 'undefined') && (sforce != null) ) {
// do your SF1 mobile button stuff
}
else {
// do your desktop stuff
}
There isn't an official way to do a server side check. See this twitter conversation for more, where the following gist by TehNrd (Jason Venable) is referenced which checks for the presence of certain parameters.
//Determine if this is SF1 app
public static Boolean isSF1(){
if(String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameHost')) ||
String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameOrigin')) ||
ApexPages.currentPage().getParameters().get('isdtp') == 'p1' ||
(ApexPages.currentPage().getParameters().get('retURL') != null && ApexPages.currentPage().getParameters().get('retURL').contains('projectone') )
){
return true;
}else{
return false;
}
}
There is also an Idea,"Provide a supported url param to determine if page is in SF1", on the Idea Exchange.