Android Question [B4A] Logout before uninstall

Alejandro Moyano

Member
Licensed User
Hi, I developed an app who send personalized alarms set in the app, then the application register the device FCMTOKEN when the device login, and delete from the server when the user logout.

Lately, I receive complaints of ex-users receiving their alarms, the main reason is that they just uninstall the app, and as is a JWT stateless app, the app is always logged.

My solution was tried to create a service to verify the uninstallation and delete the token from the server, to do it I created a module:

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public broadcastIntent As Intent
    Public broadcastIntentID As String
End Sub

Sub Service_Create

    broadcastIntentID = "android.intent.action.ACTION_PACKAGE_FULLY_REMOVED"  ' must match the Manifest entry

End Sub

Sub Service_Start (StartingIntent As Intent)

    Log("Intent Action: "&StartingIntent.Action&" looking for: "&broadcastIntentID)
    If StartingIntent.Action = broadcastIntentID Then
        Wait For (REST.API.LogOut) Complete (Success As Boolean)
        Service.StopAutomaticForeground
    End If
End Sub

Sub Service_Destroy

End Sub

send set this values on the manifest:

B4X:
'Unintall checkout
AddReceiverText(BroadcastReceiverService,
<intent-filter>
    <action android:name="android.intent.action.ACTION_PACKAGE_FULLY_REMOVED" />
</intent-filter>)


But seems not be working, am I doing something wrong?
 

Alejandro Moyano

Member
Licensed User
The only way to intercept this intent, when your app is uninstalled, is with a second app.
You cannot do anything when your app is uninstalled.

Are you sending push messages? Once the app is uninstalled the user will not receive any new messages.
Yes, but I'm not using the group:

On the firebase messaing I have this code:

B4X:
Public Sub SetApiRestToken
    REST.API.FirebaseCloudMessagingToken = fm.Token
End Sub

and on the login this one:

B4X:
Private Sub resumRegistrarDispositivo As ResumableSub
    Dim post As HttpJob
    Dim root, jsonMap As Map
    Dim parser As JSONParser
       
    If fbcmToken <> "" Then
        jsonMap.Initialize
        jsonMap.Put("fcmToken", REST.API.FirebaseCloudMessagingToken)
        post.Initialize("Insert", Me)
        post.PostMultipart($"${REST.API.URL}/aus/fcmToken"$,jsonMap,Null)
        post.GetRequest.SetHeader("Authorization",$"Bearer ${REST.API.AccessToken}"$)
        post.GetRequest.SetHeader("Grants",$"${REST.API.Grants.Trim}"$)
        Wait For (post) JobDone (post As HttpJob)
        If UTILS.IsTrue(post.Success) = True Then
            Log(post.GetString)
            parser.Initialize(post.GetString)
            root  = parser.NextObject
            Message = root.Get("message")
            idFCMToken = root.Get("idFCMToken")
            APPCODE  = root.Get("app_code")
        Else
            Message = "Error al intentar acceder al servidor"
            APPCODE  = REST.API.APPCODE_ExceptionError
        End If
        post.Release
    Else
        Message = "El dispositivo no puede recibir notificaciones."
        APPCODE  = REST.API.APPCODE_Ok
    End If  
    Return APPCODE
End Sub

Then the messages are sent directly from the server to the device throw FCM, for example if the user set an alarm when temperature reach X the message will be delivered to all logged devices of the user.

Another problem is the risk of been sending thousands of messages that are rejected.

Haves the Token a device+app binding?
 
Upvote 0

Alejandro Moyano

Member
Licensed User
OK, then I can set a logic likes X attempts to delete the token ex:

After 5 delivery attempts, register the uninstallation of the device and delete the token.

I know that it's not a 100% real metric because there are people who will install the app but never register an alarm. But it's a good to know how many real users delete the app and email them to ask why are they leaving. Would be great to improve the app.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…