[Android] Detect the firmware version (1.x or 2.x) of the Pebble

Pebble SDK 2 adds functions to detect the firmware version. These versions were not present in SDK 1.
I've found a way to detect the firmware version, that works both with SDK 1 and SDK2.

I use it in my Android app (Pebble Bike) to offer the user to download the correct watchface (for fw 1.x or fw 2.x).

First of all, you need to install the new version of PebbleKit. The main difference is the presence of these new functions. It works well with fw 1.13.
https://developer.getpebble.com/2/mobile-app-guide/android-guide.html/

Here is the code to detect the firmware version:

    // try to get Pebble Watch Firmware version
    int peebleFirmwareVersion = 0;
    FirmwareVersionInfo peebleFirmwareVersionInfo;
    try {
        // getWatchFWVersion works only with firmware 2.x
        peebleFirmwareVersionInfo = PebbleKit.getWatchFWVersion(getApplicationContext());
        peebleFirmwareVersion = 2;
        if (peebleFirmwareVersionInfo == null) {
            // if the watch is disconnected or we can't get the version
            Log.e(TAG, "peebleFirmwareVersionInfo == null");
        } else {
            Log.e(TAG, "getMajor:"+peebleFirmwareVersionInfo.getMajor());
            Log.e(TAG, "getMinor:"+peebleFirmwareVersionInfo.getMinor());
            Log.e(TAG, "getPoint:"+peebleFirmwareVersionInfo.getPoint());
            Log.e(TAG, "getTag:"+peebleFirmwareVersionInfo.getTag());
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception getWatchFWVersion " + e.getMessage());
        // getWatchFWVersion works only with 2.x firmware
        peebleFirmwareVersion = 1;
        peebleFirmwareVersionInfo = null;
    }
    Log.d(TAG, "peebleFirmwareVersion=" + peebleFirmwareVersion);

Hope it can help.

Jay
Sign In or Register to comment.