Android Question DirInternal problem

gerredtor

Active Member
Licensed User
Hello, i have a problem, in wlan modus iam downloading a db file in DirInternal, but when i restart the app without a inet connection then is the db file deletet or not readable, but i dont delete it
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
It is hard to tell whats wrong with your code without more information and preferably some code snippets but this can help you
B4X:
Log(File.Exists(File.DirInternal,"yourfilename.db"))
 
Upvote 0

gerredtor

Active Member
Licensed User
this is my code:
B4X:
    If pruefeInternet Then
            StartService(Starter)
        Else
            Msgbox(File.Exists(File.DirInternal,"database.db"), "")
            StartServiceAt(StarterNoInternet, DateTime.Now + 3 * 1000, False)
    End If

and this is the Starter service:

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

Sub Process_Globals
    Dim HC As HttpClient
    'Activity is expected to set URL
    Dim URL As String
    Dim Target As OutputStream
    Dim JobStatus As Int
    Dim STATUS_NONE, STATUS_WORKING, STATUS_DONE As Int
    STATUS_NONE = 0
    STATUS_WORKING = 1
    STATUS_DONE = 2
    Dim DoneSuccessfully As Boolean
    Dim Notification1 As Notification
End Sub
Sub Service_Create
    HC.Initialize("HC")
    'Notification1.Initialize
    'Notification1.Icon = "icon" 'use the application icon file for the notification
    'Notification1.Vibrate = False
    If File.Exists(File.DirInternal, "database.sqlite") Then
        File.Delete(File.DirInternal, "database.sqlite")
    End If
 
    URL = "http://myurl/database.sqlite"
    Target = File.OpenOutput(File.DirInternal, "database.sqlite", False)
End Sub

Sub Service_Start(StartingIntent As Intent)
    'URL and Target should be set by the calling module
    Dim request As HttpRequest
    request.InitializeGet(URL)
    HC.Execute(request, 1)
    JobStatus = STATUS_WORKING
    'Notification1.SetInfo("Download Service example", "Downloading: " & URL, Main)
    'Notification1.Sound = False
    'Make sure that the process is not killed during the download
    'This is important if the download is expected to be long.
    'This will also show the status bar notification

'    Service.StartForeground(1, Null)
End Sub

Sub HC_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    'ToastMessageShow("Error downloading file: " & Reason, True)
    DoneSuccessfully = False
    Finish
End Sub

Sub HC_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    'Asynchronously download the stream
    Response.GetAsynchronously("Response", Target, True, TaskId)
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
    If Success = False Then
        'ToastMessageShow("Error downloading file: " & LastException.Message, True)
    Else
        'ToastMessageShow("Download successfully.", True)
    End If
    DoneSuccessfully = Success
    Finish
End Sub

Sub Finish
    Log("Service finished downloading")
    JobStatus = STATUS_DONE
    'Notify the activity that the download has finished.
    'It will do nothing if the activity is currently paused.
    CallSub(Main, "FinishDownload")
  '  Service.StopForeground(1) 'Return the service to the "background" (also removes the ongoing notification)
    If IsPaused(Main) Then
        'The activity is paused. The user is probably busy with some other activity.
        'Notify the user that the download has finished
        'Notification1.Sound = True
        'Notification1.SetInfo("Download Service", "Download complete", Main)
        'Notification1.AutoCancel = True
        'Notification1.Notify(1)
    End If
End Sub
Sub Service_Destroy

End Sub

and the log return false
 
Last edited:
Upvote 0
Top