Purpose – This paper aims to demonstrate that a policy-based middleware solution which facilitates the development of context-aware applications and the integration of the heterogeneous devices should be provided for ubiquitous computing environments. Ubiquitous computing targets the provision of seamless services and applications by providing an environment that involves a variety of devices having different capabilities. These applications help transforming the physical spaces into computationally active and smart environments. The design of applications in these environments needs to consider the heterogeneous devices, applications preferences and rapidly changing contexts. The applications, therefore, need to be context-aware so that they can adapt to different situations in real-time. Design/methodology/approach – In this paper, we argue that a policy-based middleware solution that facilitates the development of context-aware applications and the integration of the heterogeneous devices should be provided for ubiquitous computing environments. The middleware allows applications to track items and acquire contextual information about them easily, reason about this information captured using different logics and then adapt to changing contexts. A key issue in these environments is to allow heterogeneous applications to express their business rules once, and get the preferred data once they are captured by the middleware without any intervention from the application side. Findings – Our middleware tackles this problem by using policies to define the different applications’ rules and preferences. These policies can specify rules about the middleware services to be used, type of data captured, devices used, user roles, context information and any other type of conditions. Originality/value – In this paper, we propose the design of a flexible and performant ubiquitous computing, and context-aware middleware called FlexRFID along with its evaluation results.