ApplicationInsights-Java icon indicating copy to clipboard operation
ApplicationInsights-Java copied to clipboard

usage on Android

Open geoffrey-vl opened this issue 1 year ago • 2 comments

How can this be used in Android applications now that ApplicationInsights-Android has been deprecated? Specifically configuring the connection string is a bit non-Android. On Android you don't typically set environment variables, or put Json config files next to your appinsights jar file as there are no jar files in the end.

geoffrey-vl avatar Oct 22 '24 13:10 geoffrey-vl

For now I have something in line of this:

build.gradle:

dependencies {
    ....
    implementation "com.microsoft.azure:applicationinsights-core:3.6.1"
    implementation "com.microsoft.azure:applicationinsights-runtime-attach:3.6.1"
    ....
}

Java:

private static final String SYSPROP_CONN_STRING = "applicationinsights.connection.string";

// setup
System.setProperty(SYSPROP_CONN_STRING, connString);
com.microsoft.applicationinsights.attach.ApplicationInsights.attach();

// use
TelemetryClient client = new TelemetryClient();
client.trackEvent("somedata");
client.flush();

It fails however due to missing Java Optional class (java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Optional;). Our target platform is still running Android 5.

geoffrey-vl avatar Oct 23 '24 11:10 geoffrey-vl

Any news on this front? I've been trying to figure out a way to handle logging on android for app insights.

m-chirodea avatar Jul 17 '25 15:07 m-chirodea