Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Failed to Fetch" from localhost web server (Android 10)

ANSWERED

Hello,

 

I'm trying to achieve data communication between companion app (SDK version ~4.1.0) and a web server running on localhost (Android 10), such that some RESTful APIs can be implemented later for data storage and analysis. 

 

Currently, I'm using the kWS web server app as suggested in one of the post. I got the pro version, and started both HTTP (:8080) and HTTPS (:8081) servers (self-signed keystore.bks) with a very simple index.html. The index page can be accessed from any computer in the LAN using a web browser.

 

Next, I started the companion app to fetch data periodically with the following code:

  // send data to local server
  // fetch('https://www.google.com')            // This works!!!
  // fetch('https://127.0.0.1:8081/')           // TypeError: Failed to fetch
  // fetch('https://127.0.0.1:8081/index.html') // TypeError: Failed to fetch
  // fetch('http://127.0.0.1:8080/')            // TypeError: Failed to fetch
  // fetch('https://localhost:8081/')           // TypeError: Failed to fetch
  // fetch('http://localhost:8080/')            // TypeError: Failed to fetch
  fetch('http://127.0.0.1:8080/index.html')     // TypeError: Failed to fetch
    .then(function(response){
      return response.text();
    })
    .then(function (data) {
      if( data != undefined ) {
        console.log(data);
      }
    })
    .catch(error => {
      console.error('FetchData', error);
    });

By digging the forum, the most recent discussion I found is this, and I followed very closely. Unfortunately, I was not able to get it to work. 

https://community.fitbit.com/t5/SDK-Development/Help-with-Companion-App-Fetch/td-p/4245324

 

I also granted the access_internet permission in package.json:

{
  "devDependencies": {
    "@fitbit/sdk": "~4.1.0",
    "@fitbit/sdk-cli": "^1.7.3"
  },
  "fitbit": {
    // ...... 
    "requestedPermissions": [
      // ...... 
      "access_internet",
      // ...... 
    ],
    // ...... 
}

 

Based on the readings, it seems that 127.0.0.1 should be working on Android. I wonder if there are any updates on this fetch() error issue. 

 

Also, I'm using SDK version 4.1.0, which is the latest version supported by my Fitbit Versa 2. If it is caused by the outdated SDK, could there by any work-arounds or hotfixes?

 

Thanks a lot in advance!!

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

That's old. Can you update to the latest? I think it's 3.36

View best answer in original post

Best Answer
0 Votes
5 REPLIES 5

I switched to an older smartphone running Android 7, and it seems the fetch() is working correctly. So, more recent version of Androids are probably blocking fetch() from localhost. 

 

Other posts (Jan-2020) said that "Unsecure connections are allowed to the following explicit IP addresses only, no patterns or subnets:127.0.0.1, 192.168.0.1, 192.168.1.1, and 10.0.0.1". However, it seems other developers in this post running Android 10 also got the "Failed to fetch" error.

 

🤔Anyone got an idea how to resolve this issue for more recent Android? 🍺

 

Thanks in advance!!

Best Answer
0 Votes

I don't think the https connections are expected to work on local addresses due to certificate signing, but the http (8080) should be working. Which Fitbit mobile app version are you using with your Android 10 device?

Best Answer
0 Votes

The Fitbit App version is 3.11 (40243448).

 

Thank you!

Best Answer
0 Votes

That's old. Can you update to the latest? I think it's 3.36

Best Answer
0 Votes

Thank you!! 🍻 

 

By any chance it could be helpful for someone, here's what happened:

 

I'm developing on a Huawei P30 Lite (Android 10). After first installed from the Google Play Store, Fitbit App (version 3.36) runs smoothly. However, after being inactive (display went off) for a while, it seems that the system (App Launcher or something?) would kill the Fitbit App. Then, the Fitbit App somehow got messed up: the app CANNOT be opened anymore, with Android runtime exception:

 

Process: com.fitbit.FitbitMobile, PID: 4150
    java.lang.RuntimeException: Unable to create application com.fitbit.FitBitApplication: android.database.sqlite.SQLiteException: Can't downgrade database from version 17 to 16
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7218)
        at android.app.ActivityThread.access$2200(ActivityThread.java:296)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2208)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        // ...... a million lines ......

 

 

To revive the app, I need to either (1) uninstall/reinstall it from the Play Store, OR, (2) clear the data associated with the app. For convenience, I used the second method. This also mysteriously made the app roll back to (version 3.11), and stopped fetching from localhost. 

 

I found a solution in this post, giving the Fitbit app an exception in the App Launcher. This seems to prevent the app from being killed by the system, not messing up with the SQLite database, and thus allowed me to keep using version 3.36. 😕

 

Update: nope, the app starts crashing again. 🤐

Best Answer
0 Votes