VanLan
VanLan

Reputation: 23

Get Android version number with forge (trigger.io)?

Is there any way to get the Android version currently running in a trigger.io app? I'm attempting to maximize performance by removing some css flare (drop shadows and gradient) for older versions of Android.

Upvotes: 1

Views: 252

Answers (1)

Patrick Rudolph
Patrick Rudolph

Reputation: 2241

UPDATE: The module I described below has just been made public, so feel free to use forge.platform.


I actually wrote a native module for Trigger.io apps that is doing exactly this. The code of my API.java looks somewhat like this:

package io.trigger.forge.android.modules.version;

import io.trigger.forge.android.core.ForgeTask;

public class API {
  public static void getAPILevel(final ForgeTask task) {
    task.success(android.os.Build.VERSION.SDK_INT); // e.g. "17"
  }

  public static void getVersionString(final ForgeTask task) {
    task.success(android.os.Build.VERSION.RELEASE); // e.g. "4.2.1"
  }

  public static void getDeviceName(final ForgeTask task) {
    task.success(android.os.Build.MODEL); // e.g. "Nexus 7"
  }
}

Update: You can now find the code on a public GitHub repo as well.

Of course, this will only work for native apps. If you deploy you project to the web, you'll need to have a fallback that parses the user agent.

Upvotes: 2

Related Questions