Skip to main content
1-Visitor
June 14, 2021
Question

Connectivity problem on Android App [Java SDK]

  • June 14, 2021
  • 1 reply
  • 1309 views

Hello, 

 

Recently, I had a Java app made with the PTC Java SDK (JAVA-SDK-6-2-0-220). I used the SimpleClient provided by PTC, and I successed to interract with the server.

 

Later I move this code to an Android App, with the same PTC Java SDK, and I can't connect. Here are the versions i tried : 

 

Version Android : API 30: Android 11
Version Java JDK (from Android Studio) : 11.0.8
Version SDK PTC Thingworx : JAVA-SDK-6-2-0-220
result : failure


Version d'Android : API 29: Android 10
Version Java JDK (from Android Studio) : 11.0.8
Version SDK PTC Thingworx : JAVA-SDK-6-2-0-220
result : failure

 

The exact same code is working well on Java with Eclipse (still same ptc java sdk)

 

Here are the authorization i requierd. I don't prompt the user to accept it, as i think the 3 first doesn't require user aprobation. The 2 I'm not even sure I need them. 

 

 

 

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
// To fix EACCES error (this had not fixed the issue)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

 

 

 

Here is my code (simplified)

The trace is in the file attached.

 

 

public class SimpleClient extends ConnectedThingClient {

 private static final Logger LOG = LoggerFactory.getLogger(SimpleClient.class);

 private static String ThingName = "AndroidTestThing";

 public SimpleClient(ClientConfigurator config) throws Exception {
 super(config);
 }

 public static void notifyServer() {

 ClientConfigurator config = new ClientConfigurator();

 config.setUri("wss://xxxxxxxxxxxxxxxx:443/Thingworx/WS");
 config.setAppKey("xxxxxxxxxxxxxxxxxxxxxxxxxx");
 config.ignoreSSLErrors(true);

 try {
 SimpleClient client = new SimpleClient(config);

 client.start();

 // Wait for the client to connect.
 if (client.waitForConnection(30000)) {
 LOG.info("The client is now connected.");
 } else {
 LOG.warn("Client did not connect within 30 seconds. Exiting");
 }

 client.shutdown();

 } catch (Exception e) {
 LOG.error("An exception occurred while initializing the client", e);
 } finally {
 LOG.info("SimpleClient is done. Exiting");
 }
 }
}

 

 

 

 

 

 

 

 

1 reply

1-Visitor
June 15, 2021

Edit : I tried with this settings, and the setAppKey method is not referenced. 

Version d'Android : API 29: Android 10
Version Java JDK (from Android Studio) : 11.0.8
Version SDK PTC Thingworx : JAVA-SDK-7-0-0-1485 (from https://developer.thingworx.com/en/sdks)
**Résultat : methode .setAppKey unknown**

NB_9778056_0-1623745492418.png

 

Community Manager
June 17, 2021

Hi @NB_9778056.

 

For troubleshooting:

 

  1. Have you tried without SSL
  2. How are you connecting?  Are you on the same network or on the mobile network?  You could try it both ways to see if there is a connectivity issue.

Also, did you check the Android examples provided with the JAVA-SDK-7-0-0-1485 version that you last downloaded?

 

Regards.

 

--Sharon