2021 Update Rollup 1

Android API ReferencePermanent link for this heading

Since version 2013 Winter Release the Fabasoft app.telemetry SDK was extended to also support mobile devices. In this case Android apps can be instrumented using the Fabasoft app.telemetry SDK for Android.

This SDK for Android is very similar to the basic Java SDK (see “Java API Reference”) with 2 exceptions:

  1. The data transport is HTTPS-based. Instead of relying on a native library to communicate with the app.telemetry agent, the mobile SDK uses HTTPS-network calls to communicate with the Fabasoft app.telemetry WebAPI (which forwards the data to the Fabasoft app.telemetry Agent).
  2. Most API-methods require a thread-token as an additional parameter.

Additionally the Android SDK provides a helper function to create a screenshot from the device screen that could be sent with your feedback: APM.createScreenshot().

Prerequisites for Instrumenting Android Java AppsPermanent link for this heading

In order to use the Fabasoft app.telemetry SDK for mobile devices (Android) you will need an installation of Fabasoft app.telemetry (Server, Agent + WebAPI) and ensure that the WebAPI web service is reachable from your mobile device by checking the WebAPI status page of your installation (https://<your server>/web.telemetry). This installation will receive the telemetry data and will be used to configure the infrastructure (agent, log pools, etc.).

Before starting to develop anything for your mobile device, you will need a development environment for Android and all device drivers to communicate with your device.

Configuration for Android Java AppsPermanent link for this heading

The next required step is to include the Fabasoft app.telemetry SDK library for Android (softwaretelemetry-android.aar) as additional library into your project. This library is delivered with the app.telemetry installation media in the “Developer/Android” folder. The JavaDoc is next to the archive in a jar file (softwaretelemetry-android-javadoc.jar).

Instrumenting Android Java AppsPermanent link for this heading

The technical background for instrumenting any Java-based application is already described in chapter “Java API Reference”.

In order to initialize the SDK for your mobile app you need to pass the Android app “Context” and the target URL of your app.telemetry WebAPI instance.

Syntax

static final String WEBAPI_URL = “http://<your server/web.telemetry”;
IAPMDataTransport transport = new MyDataTransport()
APM.init(this.getApplicationContext(), WEBAPI_URL, transport);
APMApplication app = APM
.RegisterApplication("Fabasoft app.telemetry", "Test Application", "Android", "Test 1");

The differences about how to use this API for an Android-based Java application can be obtained from the sample project.

Usage Example (APMDemoApplication.java)

package com.example.feedback;

import android.net.Uri;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;


import com.apptelemetry.apm.client.APM;

import com.apptelemetry.apm.client.APMModule;

import com.apptelemetry.apm.client.APMReportContent;

import com.apptelemetry.apm.client.IAPMDataTransport;

import com.apptelemetry.apm.client.IAPMDataTransportResponseCallback;


import android.view.View;

import android.widget.EditText;

import android.content.Intent;


public class MainActivity extends AppCompatActivity {

  APMModule moduleEvent;

  //change the following URL to YOUR app.telemetry server/WebAPI

  //it is the URL where the telemetry data and the feedback is sent to
  
static final String WEBAPI_URL = "https://<server>/web.telemetry";

  
@Override
  
protected void onCreate(Bundle savedInstanceState) {
    
super.onCreate(savedInstanceState);
    
setContentView(R.layout.activity_main);
    
APM.init(this.getApplication(), WEBAPI_URL, new MyDataTransport());
    
APM.RegisterApplication("Fabasoft app.telemetry", "Test Application",
"Android", "Test 1");
    
moduleEvent = APM.getModule("Event");
    
moduleEvent.RegisterEvent(1001, "sendFeedback", "message");
    
moduleEvent.RegisterEvent(1002, "secondThread", "message");
  
}
  
public void sendFeedback(View view) {
    
APMReportContent screenshot = APM.createScreenshot(view);
    
long thread = APM.CreateContextTx(0, "sendFeedback");
    
Intent intent = new Intent(this, FeedbackDialogActivity.class);
    
EditText editText = (EditText) findViewById(R.id.edit_message);
    
moduleEvent.EventStrTx(thread, 1001, APM.EVENT_LEVEL_NORMAL, APM.FLAG_ENTER, editText.getText().toString());
    
byte[] contextToken = APM.GetContextTx(thread);
    
long thread2 = APM.AttachContextTx(0, contextToken);
    
moduleEvent.EventStrTx(thread2, 1002, APM.EVENT_LEVEL_DETAIL, APM.FLAG_ENTER, editText.getText().toString());
    
moduleEvent.EventTx(thread2, 1002, APM.EVENT_LEVEL_NORMAL, APM.FLAG_LEAVE);
    
byte[] syncMark = APM.GetSyncMarkTx(thread2);
    
APM.ReleaseContextTx(thread2);
    
APM.SetSyncMarkTx(thread, syncMark);
    
String message = editText.getText().toString();
    
intent.putExtra(FeedbackDialogActivity.EXTRA_SCREENSHOT, screenshot);
    
intent.putExtra(FeedbackDialogActivity.EXTRA_TOPIC, message);
    
startActivity(intent);
    
moduleEvent.EventTx(thread, 1001, APM.EVENT_LEVEL_NORMAL, APM.FLAG_LEAVE);
    
APM.ReleaseContextTx(thread);
  
}
}

class MyDataTransport implements IAPMDataTransport {
  
@Override
  
public boolean isNetworkConnected() {
    
return true;
  
}
  
@Override
  
public boolean sendData(Uri uri, String contentType, byte[] bytes, IAPMDataTransportResponseCallback callback) {
    
// TODO: your implementation here
    
MyResponseObject response = sendHttpPostRequest(uri, contentType, bytes);
    
callback.dataSent(response.getStatus(), response.getContentType(), response.getResponseStream());
    
return true;
  
}
}