Workaround the NetworkOnMainThread exception
Android 4+ doesn't allow applications to make network calls on the main thread. There is a good reason for this restriction as such calls cause the UI to freeze and after 5 second Android will show the "Application not responding" dialog. Proper libraries take care of handling network calls...
www.b4x.com
เพิ่มโค้ดต่อไปนี้เข้าไป
B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
DisableStrictMode
End If
End Sub
Private Sub DisableStrictMode
'This was recommended to make the FCM work. Fix the error. Called from if first time.
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