Expand my Community achievements bar.

AEM detect the device from which the request came?

Avatar

Former Community Member

I want to achieve is, When a mobile device sends the request to the page it captures the attributes of mobile like mobile browser, mobile browser version, mobile OS and mobile OS version. I want to LOG this information and in later stage use this to categorize them in different Device Group and render different components in different device groups.

Note I have already gone through some of these links CQ5 Mobile Development Docs

http://www.cognifide.com/blogs/cq/adobe-cq-5-5-mobile-improvements/http://wurfl.sourceforge.net/help_doc.php

I have tried this code which throws Null Pointer Exception since the device variable has a null value. Correct me if I am doing wrong somewhere

SlingHttpServletRequest slingRequest = this.request.getSlingRequest();Device device = slingRequest.adaptTo(Device.class);     if(device != null) {         DeviceGroup deviceGroup = device.getDeviceGroup();         Collection<DeviceCapability> capabilities = deviceGroup.getCapabilities();         Map<String,String> deviceAttributes = device.getAttributes();         String userAgent = device.getUserAgent();         out.write(userAgent + "  inside if\n");     }     out.write("  Test\n");

Here is the way I am testing this code, whenever a request is sent to the page which has this component which write the attributes of the mobile device. I am using emulators in google chrome.

Please help me out if I am going wrong in the code or method to get the mobile device's attributes. Please let me know if you need more details on this.

2 Replies

Avatar

Employee

Have you connected a JAVA remote debugger to inspect the request object on the server? 

Avatar

Former Community Member

I was checking in the chrome devtools to check the request user agent. User agent was showing as iPhone. I'm using CQ 5.5.2 version.

Thank You for the response. Please help me in getting through this issue.