B4A Library Amir_TileService

Another B4A Library šŸ¤©

Amir_TileService (#B4A)
Quick Settings Tiles

Medium | Ian Lake said:
Requiring that a user open your app is so 2008. Widgets and notifications have been around since the early days of Android to provide additional surfaces for displaying important controls and information from your app even when the app isnā€™t open. New in Android 7.0 (API 24), any app can now create a quick settings tile for quick access to critical pieces of functionality available above the notification tray.


Tiles gives the user quick access to a specific task or functionality of the app without opening the app itself,
improving the productivity and overall user-experience of the app.

Building a TileService :
1. Create an StandardClass for TileService Events :

Private Sub Class_Globals
End Sub

Public Sub Initialize (TileService As Amir_TileService)
    'Amir_TileService will create and initialize this class!
End Sub

Private Sub TileService_Clicked (TileService As Amir_TileService)
    'Called when the user clicks on this tile.
End Sub

Private Sub TileService_Added (TileService As Amir_TileService)
    'Called when the user adds this tile to Quick Settings.
End Sub

Private Sub TileService_Removed (TileService As Amir_TileService)
    'Called when the user removes this tile from Quick Settings.
End Sub

Private Sub TileService_StartListening (TileService As Amir_TileService)
    'Called when this tile moves into a listening state. (when the Tile becomes visible)
End Sub

Private Sub TileService_StopListening (TileService As Amir_TileService)
    'Called when this tile moves out of the listening state. (when the tile is no longer visible)
End Sub

2. Manifest Codes
    <meta-data android:name="com.aghajari.tileservice.TileService"
               android:value="$StandardClassName$" />
        <action android:name="android.service.quicksettings.action.QS_TILE" />
Icon : default tile icon (Ex: android:icon="@android:drawable/ic_media_play")
Label : default tile label
StandardClassName : name of the class that you created in first step

And we are done! šŸ„³

You can update the Tile info from the class events. Example :
Private Sub TileService_Clicked (TileService As Amir_TileService)
    Dim Tile As Amir_Tile = TileService.QsTile
    Tile.State = Tile.STATE_ACTIVE
    Tile.Icon = Tile.CreateIconWithAndroidResource("ic_media_pause")
    Tile.Label = "Connected"
    Tile.ContentDescription = "AmirTileService"
End Sub

You can request an update for tile whenever you want . Example :
Dim p As Phone
If p.SdkVersion>=24 Then
    Dim TS As Amir_TileService
End If

Tile States :
Depending on the state of the Tile, the icon will automatically be tinted.

Quick Settings Tiles supports Android 7.0 (API 24) and above!
Document : https://developer.android.com/reference/android/service/quicksettings/TileService
also read about quick settings tiles in Medium

Lib+Sample attached :)


  • Amir_TileService.zip
    16.9 KB · Views: 144