Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 22.214.171.124 release ready!
Owner and Founder. Opencart
Floating chat head is nothing but the view that is drawn over other applications. Android system allows applications to draw over other application if the application has android.permission.SYSTEM_ALERT_WINDOW permission. We are going to use the background service to add the floating widget into the view hierarchy of the current screen. So, this floating view is always on top of the application windows.
To drag the view across the screen we are going to override OnTouchListener() to listen to drag events and change the position of the view has in the screen.
In this manifest you can we have a user-permission android:name=”android.permission.SYSTEM_ALERT_WINDOW” that is responsible for adding the overlay layout.
As you can see we have also declared.MyFloatingWindowService in the service tag. That is the Started service that is for managing our touch events on overlay floating window when our app is in the background state.
In our MainActivity, As you can see we have a button in activity_main.xml layout we are performing two tasks on click of it.
1- We check that is Build version is greater then Marshmallow and is app have the permission of overlay.
2- Simply start the service that we created in the next step and after starting the service we finish the activity.
In our service class first thing to do is we need to initialize a window manager object because we add the layout or view on it.
We need to call the getSysytemServices method and its parameters we pass Context.WINDOW_SERVICE to initialize WindowManager object.
Also, we need to initialize the Window Manager layout params.
At this point please take a look at LAYOUT_FLAG initialization above comment because it can through Exception.
Now getting the view by the help of LayoutInflater and after getting the view we add that view in our window manger object with layout params.
Now we can achieve the overlay but for handling the touch event on that popup window we need to setOnTouchLlistner on that view or you can set any child view of that view.
In my case I have an image view in my floating view that’s id is chat_head.
I setOnTouchListener on it and manage the touch events in onTouch callback.
Now we achieved Floating Chat head like facebook in android using Kotlin.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
are you want to see the activity_main.xml?
It was a successful collaboration. The Mobikul team provided the client everything they needed in a timely and high-quality manner. They were very professional, reliable, and accessible during the entire process. The client also saw no room for any improvements in the vendor's performance.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.