Android Question java.io.UnsupportedEncodingException

HARRY

Active Member
Licensed User
Longtime User
Hi,

My B4A program using asyncstreamstext writes a simple text: Main.Stream2.write("Start") to a B4J program also using asyncstreamstext. The error mentionned above is reported. I have searched this forum, but have not found a solution. Can somebody help me?

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hi Erel,
The problem has been solved. The only change I made, as far as I remember, is that I have set the target SDKversion to 28 and the same in the file paths. They were different. I don't understand, but it works now.
Harry
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It is a mistake to use targetsdk 28. Use 26 max for now.
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
The problem reappeared. Following the suggestion of DonManfred, I changed to targetsdk 26. No improvement.
The code concerned is:
in MAIN:
B4X:
#Region  Project Attributes
    #FullScreen: True
    #IncludeTitle:false
    #ApplicationLabel: ViewCamera
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: True
    #BridgeLogger:true
#End Region

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

Sub Process_Globals
    Public SourceImageRect, TouchImageViewRect As Rect   
    Dim samsung As Phone   
End Sub

Sub Globals
    Public  TouchImageView1 As TouchImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    Activity.LoadLayout("1")
    samsung.SetScreenOrientation(8)
    TouchImageView1.Initialize("TouchImageView1")
    Activity.AddView(TouchImageView1, 0, 0, 640dip, 480dip)
    TouchImageView1.Gravity=Gravity.FILL
    StartService(Stream1Service)
End Sub

Sub Activity_Resume   
                
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed=True Then
        If Stream1Service.stream1.IsInitialized Then Stream1Service.Stream1.Close
        If Stream1Service.Client1.IsInitialized Then Stream1Service.Client1.Close
        If Position.Stream2.IsInitialized Then Position.Stream2.Close
        If Position.Client2.IsInitialized Then Position.Client2.Close
        Activity.finish
    End If
End Sub

Sub Display ( in  As InputStream)
    Dim bmp As Bitmap
    bmp.Initialize2(in)
    TouchImageView1.SetBitmap(bmp)
    SourceImageRect.Initialize(0, 0, bmp.Width,bmp.Height)
    TouchImageViewRect.Initialize(0, 0, TouchImageView1.Width,TouchImageView1.Height)
    TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")
    Return
End Sub
In Stream1Service:
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.
    Private WiFi As MLwifi
    Public Stream1 As AsyncStreams
    Public Client1  As Socket   
    Public local As Boolean
    Private mHost As String
    Private mPath As String= "/?action=stream"
    Private Data(1000000) As Byte
    Private index As Int
    Private bc As ByteConverter
    Private boundary As String
    Public curpos As Int =90
End Sub

Sub Connect
    If Stream1.IsInitialized Then Stream1.Close
    If Client1.IsInitialized Then Client1.Close
    
    If WiFi.IsWifiConnected= True And (WiFi.SSID="JetStream" Or WiFi.SSID="JetStream1") Then
        local=True       
        Client1.Initialize("Client1")
        Client1.Connect("192.168.2.4",8080, 20000)
        mHost="192.168.2.4:8080"
    Else
        local=False       
        Client1.Initialize("Client1")
        Client1.Connect("00.000.000.00",44000, 20000)
        mHost=00.000.000.00:44000"
    End If
    
End Sub

Sub Service_Create
    Connect
End Sub

Sub Service_Start (StartingIntent As Intent)   
    'Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

Sub Service_Destroy

End Sub

Sub Client1_Connected (Successful As Boolean)
    If Successful Then
        If Stream1.IsInitialized Then Stream1.Close
        Stream1.Initialize(Client1.InputStream,Client1.OutputStream,"Client1")
        If local =True Then
            ToastMessageShow("Verbinding via WiFi", True)
        Else
            ToastMessageShow("Verbinding via internet", True)
        End If
        boundary = ""
        Dim sTmp As String = $"GET ${mPath} HTTP/1.1
Host: ${mHost}
Connection: keep-alive

"$
        Successful= Stream1.Write(sTmp.Replace(Chr(10), CRLF).GetBytes("UTF8"))
    Else
        Log("Connection error")
        Return
    End If
End Sub

Private Sub Client1_NewData (Buffer() As Byte)
    If IsPaused(Main) =False Then
    bc.ArrayCopy(Buffer, 0, Data, index, Buffer.Length)
    index = index + Buffer.Length
        If boundary = "" Then
            Dim i1 As Int = IndexOfString("Content-Type", 0)
            If i1 > -1 Then
                Dim i2 As Int = IndexOfString(CRLF, i1 + 1)
                If i2 > -1 Then
                    Dim ct As String = BytesToString(Data, i1, i2 - i1, "ASCII")
                    Dim b As Int = ct.IndexOf("=")
                    boundary = ct.SubString(b + 1)
                End If
            End If
        Else
            Dim b1 As Int = IndexOfString(boundary, 0)
            If b1 > -1 Then
                Dim b2 As Int = IndexOfString(boundary, b1 + 1)
                If b2 > -1 Then
                    Dim startframe As Int = IndexOf(Array As Byte(0xff, 0xd8), b1)
                    Dim endframe As Int = IndexOf(Array As Byte(0xff, 0xd9), b2 - 10)
                    If startframe > -1 And endframe > -1 Then
                        Dim In As InputStream
                        In.InitializeFromBytesArray(Data, startframe, endframe - startframe + 2)
                        CallSub2 (Main,"Display",In)
                    End If
                    TrimArray(b2)
                End If
            End If
        End If
    End If
End Sub

Private Sub TrimArray (i As Int)
    bc.ArrayCopy(Data, i, Data, 0, index - i)
    index = index - i
End Sub
Private Sub Stream1_Error
    Log("Stream1 Error")
End Sub

Sub TouchImageView1_Click(X As Int, Y As Int)
StartActivity(Position)
End Sub

Sub TouchImageView1_LongClick(X As Int, Y As Int)

End Sub[/CODE]
The error information is in the errorinformation.txt file


I hope this information is enough to solve the problem

Harry
 

Attachments

  • errorinformation.txt
    94.1 KB · Views: 185
Upvote 0
Top