Foreground Service with Overlay Icon Android || Android 13
Channel: Serial Coder
Date: 01/06/2023

Here is the full sample of Foreground Service with overlay icon in android 

it will work on all the updated android versions including android 12 and android 13.

follow the steps for creating foreground service using Android.


 Java Class

1. Create a new Android Project.
2. And according to me add these permission in AndroidManifest file
    uses-permission android:name="android.permission.FOREGROUND_SERVICE"
    uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"

3. And add your service in androidmanifest.
     service
        android:name="com.example.myservice.GeanieView"
        android:enabled="true"
        android:exported="false" 

3. Manage screen overly permission in MainActivity.
4. Create a your Service class and extends Service.
5. Create a (GeniePositonsSaver class) #Your class name# and Handel the Screen    overly  View.
6. To remove the view of your screen overlay create a new class like my class is    ASSL.
7. Create a SimpleAnimator class and handle the bottom remove view Animation.
8. Create a (Common class) MyApplication class and handle your service like    onResume/onDestroy etc.
 
9. And add your (Common class) in AndroidManifest.Like
     application
        android:name="com.example.myservice.MyApplication"
        android:enableOnBackInvokedCallback="true" 
     

===== Layout's=====

1. You can create a custom dialog so that we  get screen overlay permission.
2. You can create a layout and design it accordingly by making a gradient.  This    will be your remove layout.
3. Create a new layout that will appear on your screen.

===== Anim file ========
 
  Create anime file inside res and design your animation properly.

Here is the link of project:

https://drive.google.com/file/d/19bHWDWfu0zI1KHdxGRl50_t3yznNyn-q/view?usp=sharing