I don't understand. Does it raise an error or not?
When installing my APP in Android 7.0 it no longer connected with my device, which uses an ESP8266 module in Access Point mode (without Internet access), but always worked with previous versions of Android.
In the search for the reason for not connecting I incorrectly interpreted that Android 7.0 did not enable the permissions of total access to the Internet, since in previous versions of Android that permission was shown in a list, and in version 7.0 only the Storage permission was shown.
Each time I tried to send a data packet using the TxString function detailed above (belonging to a Service module called TCP), the portion of Catch code that closed the connection was executed.
I added the function in the Catch:
ToastMessageShow(LastException.Message, True)
Which returns the following message:
android.os.NetworkOnMainThreadException
Which took me to the next Thread:
Based on this Thread I was able to solve my connection problem by executing the following function in the Main:
Sub DisableStrictMode
Dim jo As JavaObject
jo.InitializeStatic("android.os.Build.VERSION")
If jo.GetField("SDK_INT") > 9 Then
Dim policy As JavaObject
policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
Dim sm As JavaObject
sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
End If
End Sub
Anyway, I think I understand that this is not the best solution, and that this error occurs by calling network functions from the Main.
I am currently calling the network functions (belonging to a Service module) from the Main, for example, as follows:
CallSubDelayed(TCP, "TxCmdS")
Please, Which would be the correct way to execute network functions that start from an event generated by the User from the Main window?
Thank you very much !