Android Question Print to IP Adresse

Babo

New Member
Licensed User
Hello how can i print over the IP Adress? I try this, but it dont work.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Print_on_IP
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim Socket1 As Socket
    Dim Printer1 As TextWriter
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    Activity.LoadLayout("1")
    
    Socket1.Initialize("Socket1")
    Socket1.Connect("192.168.100.202", 9100, 20000)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Socket1_Connected (Successful As Boolean)
    If Successful = False Then
        Msgbox("Error", "")
        Return
    End If
    
    Printer1.Initialize(Socket1.OutputStream)

    Msgbox("Connected", "")
End Sub

Sub Button1_Click
    Printer1.WriteLine("Testrow")
        
    Msgbox("Print", "")
End Sub
 

Babo

New Member
Licensed User
It is so easy with Java! Is Java the better Way?

B4X:
try
    {
    Socket sock = new Socket("192.168.1.222", 9100);
    PrintWriter oStream = new PrintWriter(sock.getOutputStream());
        oStream.println("HI,test from Android Device");
        oStream.println("\n\n\n");
        oStream.close();
        sock.close();
    }
    catch (UnknownHostException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top