2

Requirement is to add a chat feature in the app, that would be available across all activities in minimized view once initiated - you can start a chat within one activity and keep it live when changing activities.

Solution -> Use this permission, and create a service, to overlay across all screens.

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Problem with the requirement we have -> 

  1. We don't need a view visible over all applications - a view visible only to our app.
  2. Using the above solution requires run time permission from users for api level above >=M.
  3. User can disable this permission from settings, and overlay won’t work.



Is there any way i can achieve this without using this Permission and Service.

Ritt
  • 3,181
  • 3
  • 22
  • 51
  • 1
    "that would be available across all activities" -- switch to fewer activities, whether using fragments or something else. "Problem with the requirement we have" -- in addition to those problems, that permission is not available on all devices, and I suspect that it will be retired in a year or two. – CommonsWare Jul 30 '20 at 00:02
  • Yes I agree. I am working on the codebase, where i cannot switch to fewer activities. Wondering if i can add the custom-view to the root view of window and it will be available across all or if theres any other way. – Ritt Jul 30 '20 at 00:08
  • "Wondering if i can add the custom-view to the root view of window and it will be available across all or if theres any other way." -- not that I am aware of. – CommonsWare Jul 30 '20 at 00:12
  • I dont see a straight forward solution. I can make use of base-activity, which already exists but that will be removed in future. My chat feature is more like different module/library independent of main module. And a simple launchChat() should take care of everything. – Ritt Jul 30 '20 at 00:16
  • 1
    This is precisely why using activities as your abstraction point for screens is a bad idea. – ianhanniballake Jul 30 '20 at 00:26
  • @ianhanniballake Yeah, I agree. I am not a big fan of keeping base classes like here activity. Reason, I am not taking this BaseActivity path. There are many downside to this, one is, for my feature to be available, all other new activities need to extend from Base. – Ritt Jul 30 '20 at 00:34
  • I wonder how google created bubble chat-head without using this permission overlay approach. – Ritt Jul 30 '20 at 00:36
  • 1
    @CommonsWare I was able to solve it using Application.ActivityLifecycleCallbacks. This will give you call backs for all activities an you can attach the custom view. – Ritt Jul 30 '20 at 20:33
  • Doesn't that result in some amount of flicker? I dismissed that sort of solution, figuring that you were looking for something that simply never went away. But, if it works for you, that's great! – CommonsWare Jul 30 '20 at 20:37
  • Drag drop animation and on/off the view, i am working on it. Not sure if i will face the flicker effect. I will circle back if it does. What do you think of chat-bubble if i need to implement without using the above permission. – Ritt Jul 30 '20 at 20:45
  • @CommonsWare I achieved minimized view with ActivityLifeCycleCallBack, attach and deattach in onResume and onPause. Haven't explored services much. Wondering if i can achieve the same using service bound to application process? – Ritt Aug 16 '20 at 05:53
  • @Ritesh: Check https://localazy.com/blog/floating-windows-on-android-1-jetpack-compose-and-room for the tutorial on how to make chat-head like bubbles and windows floating over other apps. – Václav Hodek Sep 26 '20 at 10:41

0 Answers0