App (TCP) works in Win10 and Android Simulator but not in device !NOT WORKING below ANDROID4.4

Hi all,

I can't find the problem.

I am trying to run an app, it creates a TCP client socket and  communicates with a microchip uC device (server) and sends some bytes (using port 1001).

It works flawless in windows10 and using the simulator android studio, but when i download into the smartphone it doesn't work, the TCP connection is never carried out (every time I press a button it tries to connect with timeout of 3000ms).

All permissions are selected (and i see them in the manifest). Maybe is any of my smartphone settings??i can't find it out.

 

By the way, there is a field in juce for Custom permissions??so you know how to write them??kind of...
android:screenOrientation="landscape"

Best regards and thanks in advance, I am stuck with

Carlos

I have tried also adding....

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 

but no way to make it work :(

 

Just in  case, my android version is 4.2.2 (API17)....

 

try android.permission.INTERNET perhaps?

Hi, 

Yes, I already had it,  i have all permissions added from juce, and i can see them in the manisfest. 

therefore i added 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

which is not showed in juce.

The thing is it works perfectly in the simulator. 


<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0.0" package="com.yourcompany"> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="11"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <application android:label="@string/app_name" android:hardwareAccelerated="false"> <activity android:name="W1" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation" android:screenOrientation="landscape"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
 

I have used TCP/IP successfully on an Android phone (MQTT) - I know this doesn't help, but might help identify something else to try.

Try accessing via a different port, perhaps? (just for test purposes)

Hi, thanks for your reply.

 

Yes, i have tried 1001 and 8000 later  with no success (i had already used them successfully in other applications).

The thing is that it works flawless with the simulator and win10, therefore it is driving me nuts. Have checked lot of permissions stuff...but i dont find anything useful.

Do you know if I have to enable any feature/option in the smartphone settings??

Are you using Juce4??or former versions??

By the way, when I use the connect method with POrt, and IP as arguments...if I choose a timeout of 0....or less than <about50-100ms...I can't get the TCP connection. Is not timeout=0 for waiting even a longtime till the connection is established??

Also, I am checking packets with WireShark and the smartphone doesn't send any packet to my server when trying to connect. I seems it even doesn't get to create the socket.

 

Also I have tried bot armeabiDebug and armeabi-v7aDebug in android studio....have no idea wich the difference is... 

 

I have tried a BQ device (API17) and a Samsung (API10)....no success yet ;(

The newer Android versions have a different permissions system, which we're working to support better - could just be that..

Hi Jules, wIth newer Android versions...do you mean API 23 and so??I am testing with API10 and API17.

I mean, I think this behaviour should happen to someone else...

I can upload the project /very simple) if anyone want to help, since I am stuck here crying and I can't get on with my project without network,  is very important in mobile apps.

 

Just as a comment, if useful. I set a global variable (StreamSocket class) to handle the connection. I thought that c# and perhaps JAVA don't use global variables...so I changed this variable to belong to a class (instead of global), just in case to try, but no success either.

 

Regards

 

Carlos

Yes - the changes we're working on is just for the newer API versions, IIRC the older ones should still work if you set the permissions in the manifest.

Sorry, really don't understand your point about the global variable, or how that'd relate to java or c#..

I meant that I had a global variable in my project. And I have thought that Java doesn't use global variables, and maybe that was the problem since this global variable was the streamsocket object I was using.

I removed that global, bit it seems that wasn't the problem.

If someone wants to give a hand and replicate this I can send the juce project to see if it is "only" my problem or is compiling related. I would highly appreciate.

Regards

 

Carlos

I have read in some forums, that is better to make connections in the background since Android  is not very keen on allowing synchronous calls in the main thread or somehting like that. 

In my app i try to make the connection when I press a button. Should I try to do it in a thread??or any other better way to do something in the background??

 

Regards

 

Carlos

I have tried to make the connection in a thread, and also works in Windows and the simulator but it doesnt't in the device.

Ah yes - absolutely. I think Android prevents you don't any networking on the message thread. If you attempt it, juce would have given you an assertion, but maybe you didn't see that.

Hi, 

I am lost now, the code is very simple....just the method connect(IP,Port,timeout). 

So...where should i call it???

So far I have tried 2 methods:

************************1º method: call from button clicked

buttonclicked(){

connect();

}             

***********************2º method: notify thread from buttonclicked

buttonclicked(){

notify();

}

then the background thread:

run(){

wait(-1);

connect();

}

Both work flawless in Windows10 and Android simulator.

I don't have any assertion message in visual studio nor Android (in case it does).

It shouldn't be so difficult....it is frustating crying...I am now trying to install Android 2.0 Beta as suggested here:

http://www.juce.com/forum/topic/android-studio-tips-tricks-known-issues

***rUNNING aNDROID 2.0 Beta I get the same wrong behaviour. Should I get back to AS 1.5??

Well, I had no more ideas so I sent my APP to a friend, he has got a Samsung with Android 4.4.2 and it works!!!. So....

I have tried with no success in  a BQ Android 4.2 (API17) and Samsung Android 3.5(API10). And I am compiling for minimun SDK 10, and I have tried target 11, and 17 (android:targetSdkVersion="x")

Android 4.4                               19                              KITKAT Platform Highlights
Android 4.3                               18                              JELLY_BEAN_MR2 Platform Highlights
Android 4.2, 4.2.2                      17                              JELLY_BEAN_MR1 Platform Highlights

But it works with Android 4.4.2!!!

So....will it be due to Android version support or so??

 

Regards

Carlos

Well, after trying and trying lot of different methods (conencting in the main GUI thread, with threads, notifying threads from gui...) I can say that TCPstreaming & UDP Datagram sockets doesn't work for me (My app work as client), at least with Android below v4.4, I don't have more phones to try.

The same APP ith android 4.,4 works flawless, and so does in the Android emulator....I have activated all perssions i could activate and much more.Of course it is not the problem since it works for 4.4

When connecting TCP, the function returns error (i have tried lot of different ways, connecting in a thread, in the main gui process).

Regarding UDP I can open a port, but when trying to broadcast data, the app closes.

I would like to know if anyone else has experienced this, and I have to assume that my android apps only work above 4.4

 

Regards

 

Carlos

 

 

Regards

Carlos