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.

0*zYn9jRHUGJTkE4CB.


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 :


B4X:
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
B4X:
AddApplicationText(
<service
    android:name="com.aghajari.tileservice.TileService"
    android:icon="$ICON$"
    android:label="$LABEL$"
    android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
    
    <meta-data android:name="com.aghajari.tileservice.TileService"
               android:value="$StandardClassName$" />
    
    <intent-filter>
        <action android:name="android.service.quicksettings.action.QS_TILE" />
    </intent-filter>
</service>)
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 :
B4X:
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"
    Tile.UpdateTile
End Sub

You can request an update for tile whenever you want . Example :
B4X:
Dim p As Phone
If p.SdkVersion>=24 Then
    Dim TS As Amir_TileService
    TS.Initialize(Null)
    TS.RequestListeningState2(1)
End If

Tile States :
Depending on the state of the Tile, the icon will automatically be tinted.
1*ZkkIMFPbUec04QsJ5Rq7gA.png



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 :)
 

Attachments

  • Amir_TileService.zip
    16.9 KB · Views: 436

PJLPJLPJL

Member
Licensed User
No need to taste
Because as always, your work is great
Thanks for sharing this valuable library
Thank you this wonderful and useful library.

I think you need to add
Manifest:
    android:exported="true"
in the manifest for SDKs 31 and greater.
 
Top