Android Question Update Service

Krisalianne

Member
Licensed User
Longtime User
Hi all,
I'am trying to update a prog I've done a few year ago. The purpose is to copie a file from my tablet to a shared folder on my computer. So I have a service that used to run in background with " StartServiceAT". I understood that not the right way to it now, so I need to adjust the service. The main activity create a file pointe.txt. The service is supposed to copy this file to my shared folder in background.
Can someone help me on this, please.
Service to copy to shared folder:
#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 smbClient1 As SMBClient
    Private filna,filna1,filna2 As String
    Private now1 As Long
    Private emplrx2 As String
    Private emploc2 As String
    Private Reader As TextReader
    Private empltb2 As String
    Private emplimp2 As String
    Private Notification1 As Notification
    Private MP As MediaPlayer
    Private shared1 As String
    Private lock As PhoneWakeState

End Sub
Sub Service_Create
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
    lock.PartialLock

    Notification1.Initialize
    Notification1.Icon = "icon" 'use the application icon file for the notification
    Notification1.Vibrate = False

End Sub
Sub Service_Start (StartingIntent As Intent)
    Reader.Initialize(File.OpenInput(shared1, "Timanmay/param.txt"))
    emploc2 = Reader.ReadLine 'Emplacement local
    emplrx2 = Reader.ReadLine 'Emplacement Réseau pointage
    empltb2 = Reader.ReadLine 'Numéro de la tablette
    emplimp2 = Reader.ReadLine 'Emplacement réseau import
    Reader.Close
    'StartServiceAt( "",DateTime.now +0.2 * DateTime.ticksperminute,False)
    Service.StartForeground(1, CreateNotification("..."))
    copier
End Sub
Sub copier
    smbClient1.Initialize("SmbClient1","Timoun","timanmay","timanmay","smb:"&emplimp2)
End Sub
Sub smbClient1_Resource(success1 As Boolean, smbobjres1 As Object,smbobj1 As Object, info1 As String)
    If smbobjres1 <> Null And smbobj1 <> Null And info1 = "OK" Then
        Dim smbResource As SMBResource = smbobjres1
        smbClient1.listFiles(smbResource)
    End If
End Sub
Sub smbClient1_ListFiles (listfichiers1 As List)
    If listfichiers1.IsInitialized Then
        Dim tocopy1 As SMBFile
        If File.Exists (shared1, "Timanmay/pointe.txt") <> False Then
            If empltb2="null" Then
                empltb2 = "1"
            End If
            tocopy1=listfichiers1.Get(0)
            now1 = DateTime.now
            filna=DateTime.time(now1)
            filna=filna.replace(":","")
            filna1=DateTime.date(now1)
            filna1=filna1.Replace("/","")
            filna2 = empltb2 & "pointe"& filna1&filna
            smbClient1.Copy2(emplrx2,"pointe.txt",tocopy1,filna2 & ".txt")
            'SMB3.uploadfile(shared1, "Timanmay/pointe.txt","smb:" & emplrx,filna2 & ".txt")
        Else
            Notification1.SetInfo("Timanmay","Le PC Timanmay n'est pas disponible",Main)
            Notification1.Sound = False
            Notification1.AutoCancel = True
            Notification1.Notify(1)
        End If
    End If
End Sub
Sub smbClient1_CopyProgress(totalBytes As Long, path As String, filename As String)

End Sub
Sub smbClient1_CopyResult(success As Boolean, path As String, filename As String)
    If success Then
        File.Delete(shared1, "Timanmay/pointe.txt")
           
        MP.Initialize( )
        MP.Load(File.DirAssets, "copie.wav")
        MP.SetVolume(1, 1)
        MP.Play
    End If
        Notification1.SetInfo("Timanmay","La copie du fichier a réussi",Main)
        Notification1.Sound = False
        Notification1.AutoCancel = True
        Notification1.Notify(1)
End Sub
Sub CreateNotification (Body As String) As Notification
    Body="La copie du fichier a réussi"
    Notification1.SetInfo("Timanmay",Body,Main)
    Notification1.Sound = False
    Notification1.AutoCancel = True
    Notification1.Notify(1)
    Return Notification1
End Sub

Sub Service_Destroy
    lock.ReleasePartialLock
End Sub
 
Top