Android Question because not print in the first on of the tablet?

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello, on my app, another problem, practically or done so that it would open automatically with the boot of the Starter module enabled to true, and so far we are, being that it uses the usb printer or loaded the code in the main that at the first installation you ask for permission and then do not ask for more during use even turning on and off the device, but the strange thing is that if I turn on the tablet and after a few seconds automatically starts the app and just press the button to let out a print of a number this does not print, I have to close and re-open the app and then print without problems, I tried to disable the automatic boot of the app by starting it manually and does the same problem, what could be that every time you turn on your tablet and when the app is first started, the printer does not want to print?
I hope for your help, they all happen to me.

this my part of the code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    
    If FirstTime Then
        Server.Initialize(9092, "Server")
        Server.Listen
        Log("MyIp = " & Server.GetMyIP)
        TTS1.Initialize("TTS1")
        
    End If
 
    Activity.LoadLayout("eliminacodeWiFiUSB")
    imgsplashscreen.SetLayout(0%x,0%y,100%x,100%y)
    wifi1.Initialize("wifi1")
    wifi2.Initialize
    mp1.Initialize
    mp2.Initialize
    
    
  

    imgnext.Bitmap=(LoadBitmap(File.DirAssets,"stampaA.jpg"))
    imgB1.Bitmap=(LoadBitmap(File.DirAssets,"stampaB.jpg"))
  
    
    If File.Exists(File.DirInternal, "data.db") = False Then ' se non trova il database  allora lo copia usando il rigo di sotto altrimenti non fa nulla.
    File.Copy(File.DirAssets, "data.db", File.DirInternal, "data.db")
    Else
        
    End If
    dbsql2.Initialize(File.DirInternal, "data.db", True) ' inizializza il database
    
    productid
    vendorid
    
    'File.Delete(File.DirInternal,"data.db")
    If txtvendorid.Text ="" And txtproductid.Text = "" Then
        
        Msgbox("Attenzione devi inserire il product id e vendor id della stampante","ATTENZIONE!!!")
        
        Return
    Else
        
        If usb1.UsbPresent(1) = usb1.USB_NONE Then    ' Ver_2.4
            Msgbox("Stampante non connessa al cavo usb","ATTENZIONE!!")
            Return
        End If
    End If
        If (usb1.HasPermission(1)) Then    ' Ver_2.4
            Log(usb1.DeviceInfo(1))
            'This is very important - ( VendorId, ProductId )
            Log("PID"&txtproductid.Text) ' qui verifico se le due textbox Pid e Vid hanno assunto il valore che è stato richiamato sopra con delle sub attraverso un db.
            Log("VID"&txtvendorid.Text)
            
            usb1.SetCustomDevice(usb1.DRIVER_SILABS, txtvendorid.text ,txtproductid.text)' qui le due textbox hanno assunto i due rispettivi valori della stampante.           
                
            Dim dev As Int
            dev = usb1.Open(9600, 1) 'STMicroeletronics
            If dev <> usb1.USB_NONE Then
                Log("Connected successfully! 1")         
        
                Log("CONNECTED SUCCESSFULLY!!!")
                connected = True
                astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")

                'This is important
                usb1.SetParameters(9600, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_EVEN)
            
                'Here if you want codce that call print
            Else
                Log("Error opening USB port 1")
            End If
        Else
            usb1.RequestPermission(1)  ' Ver_2.4
        
        End If
        
          
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
with the boot of the Starter module enabled to true
This is a mistake. DO NOT use the starter service for this! Create a new service and set startatboot there...
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
This is a mistake. DO NOT use the starter service for this! Create a new service and set startatboot there...
Ok DonManfred a make a new service with boot = True but the problem is only present, when on the tablet and open the app in automatic the printer not print, if close app and reopen the printer print perfect.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I just was talking about the use of the starter service with the startonboot.

Your problem may came from another problem. But as you are not providing any useful Informations i can not answer it.

Upload a small project which shows the issue would be more helpful.
 
Upvote 0
Top