DOCUMENTATION

Android Client

To add the Logify Alert client to your application, open the application module's build.gradle file in Android Studio and do the following:

  1. In the dependencies section, add the following line to declare the logify-alert-android library dependency:

    compile "com.devexpress.logify:logify-alert-android:1.0.2"

  2. In the defaultConfig section, ensure that the minSdkVersion is set to a value from 17 to 28.

The LogifyAlert class represents the client and provides methods to do the following:

Set Up a Client

  • getInstance

    LogifyAlert getInstance()

    Initializes a new LogifyAlert class instance.

    LogifyAlert client = LogifyAlert.getInstance();

  • getApiKey

    String getApiKey()

    Returns an API Key used to register an application in the Logify Alert service.

  • getAppName

    String getAppName()

    Returns an application's name.

  • getAppVersion

    String getAppVersion()

    Returns an application's version.

  • getContext

    Context getContext()

    Gets an application's context.

  • getUserId

    String getUserId()

    Returns a unique user ID that corresponds to a sent report.

  • setApiKey

    void setApiKey(String apiKey)

    Sets an API Key used to register an application in the Logify Alert service.

    client.setApiKey("SPECIFY_YOUR_API_KEY_HERE");

  • setAppName

    void setAppName(String appName)

    Sets an application's name.

    client.setAppName("My Application");

  • setAppVersion

    void setAppVersion(String appVersion)

    Sets an application's version.

    client.setAppVersion("0.0.0.1");

  • setContext

    void setContext(Context context)

    Sets an application's context to access the application's environment information and include this information in crash reports.

    client.setContext(this.getApplicationContext());

  • setUserId

    void setUserId(String userId)

    Sets a unique user ID that corresponds to a sent report.

    client.setUserId("A unique user identifier");

Add Custom Text to Reports

The Logify Alert client provides methods to attach additional text (for example, a username, computer information, etc.) to generated reports.
A field name can only consist of a-z, A-Z, 0-9, and _ characters.

  • addCustomData

    void addCustomData(String name, String value)

    Adds custom text to a report.

    client.addCustomData("CustomerName", "Mary");

  • getCustomData

    Map<String, String> getCustomData()

    Returns a collection of custom data sent with a report.

    client.getCustomData().put("CustomerName", "Mary");

Attach Files to Reports

  • getAttachments

    List<Attachment> getAttachments()

    Returns a collection of files attached to a report. The total size of attachments is limited to 3 Mb per crash report. Each attachment should have a unique name.

    import com.devexpress.logify.alert.android.LogifyAlert;
    import com.devexpress.logify.alert.core.Attachment;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import android.os.Environment;
    
    LogifyAlert client = LogifyAlert.getInstance();
    client.setApiKey("YOUR_API_KEY");
    
    File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard, "Download/Image_to_attach.png");
    int size = (int) file.length();
    byte bytes[] = new byte[size];
    try {
        FileInputStream inputStream = new FileInputStream(file);
        inputStream.read(bytes, 0, size);
        inputStream.close();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    
    client.getAttachments().add(new Attachment("myAttachedImage.png", "image/png", bytes));

    In the AndroidManifest.xml file, add the following permission to allow your application to read data from external storage:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Add Tags to Reports

The Logify Alert client provides methods to create tags in generated reports. Tags extend the list of predefined fields used for auto-ignoring, searching or detecting duplicates.
A tag name can only consist of a-z, A-Z, 0-9, and _ characters. A new tag is added with Allow search enabled.

  • addTag

    void addTag(String name, String value)

    Creates a tag in a report.

    client.addTag("key1", "value1");

  • getTags

    Map<String, String> getTags()

    Returns a collection of report tags.

    client.getTags().put("key1", "value1");

Send Reports Automatically

  • startExceptionsHandling

    void startExceptionsHandling()

    Commands Logify Alert to report unhandled exceptions.

    client.startExceptionsHandling();

  • stopExceptionsHandling

    void stopExceptionsHandling()

    Commands Logify Alert to stop reporting unhandled exceptions.

    client.stopExceptionsHandling();

Send Reports Manually

send

Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

  • void send(Throwable ex)

    Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

    try {   RunCode(); } catch (Throwable e) {   client.send(e); }

  • void send(Throwable ex, Map<String, String> additionalCustomData)

    Sends the caught exception with custom data to the Logify Alert service.

    try {   RunCode(); } catch (Throwable e) {   Map<String, String> data = new HashMap<String, String>();   data.put("RunCode", "FailedOperation");   client.send(e, data); }

  • void send(Throwable ex, Map<String, String> additionalCustomData, AttachmentCollection additionalAttachments)

    Sends the caught exception with custom data and attachments to the Logify Alert service.

    try {
        RunCode();
    }
    catch (Throwable e) {
        Map<String, String> data = new HashMap<String, String>();
        data.put("RunCode", "FailedOperation");
        File sdcard = Environment.getExternalStorageDirectory();
        File file = new File(sdcard, "Download/Image_to_attach.png");
        int size = (int) file.length();
        byte bytes[] = new byte[size];
        try {
            FileInputStream inputStream = new FileInputStream(file);
            inputStream.read(bytes, 0, size);
            inputStream.close();
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
        AttachmentCollection attachedImages = new AttachmentCollection();
        attachedImages.add(new Attachment("myAttachedImage.png", "image/png", bytes));
        client.send(e, data, attachedImages);
    }

Handle Events

  • addAfterReportExceptionListener

    void addAfterReportExceptionListener(LogifyEventListener<AfterReportExceptionLogifyEvent> LogifyEventListener)

    Registers a listener to handle events which occur after a new crash report is sent to the Logify Alert service.

    import com.devexpress.logify.alert.android.LogifyAlert;
    import com.devexpress.logify.alert.core.events.AfterReportExceptionLogifyEvent;
    import com.devexpress.logify.alert.core.events.LogifyEventListener;
                            
    // Register an event listener with the implementation below.
    LogifyAlert.getInstance().addAfterReportExceptionListener(new AfterReportExceptionEventListener());
    // ...
    // Implement an event listner.
    class AfterReportExceptionEventListener implements LogifyEventListener {
        public void handle(AfterReportExceptionLogifyEvent event) {
            RunYourCode();
        }
    }

  • addBeforeReportExceptionListener

    void addBeforeReportExceptionListener(LogifyEventListener<BeforeReportExceptionLogifyEvent> LogifyEventListener)

    Registers a listener to handle events which occur before a new crash report is sent to the Logify Alert service.

    The BeforeReportException event occurs between the CanReportException event and sending a new report to the Logify Alert service. The BeforeReportException event is not raised if you prevent a report from being sent in the CanReportException event's handler.

    Handle the BeforeReportException event to add custom data to reports. To do this, pass the required data to the addCustomData method.

    import com.devexpress.logify.alert.android.LogifyAlert;
    import com.devexpress.logify.alert.core.events.BeforeReportExceptionLogifyEvent;
    import com.devexpress.logify.alert.core.events.LogifyEventListener;
                            
    // Register an event listener with the implementation below.
    LogifyAlert.getInstance().addBeforeReportExceptionListener(new BeforeReportExceptionEventListener());
    // ...
    // Implement an event listner.
    private class BeforeReportExceptionEventListener implements LogifyEventListener {
        public void handle(BeforeReportExceptionLogifyEvent event) {
            LogifyAlert.getInstance().addCustomData("LoggedInUser", "Mary");
        }
    }

  • addCanReportExceptionListener

    void addCanReportExceptionListener(LogifyEventListener<CanReportExceptionLogifyEvent> LogifyEventListener)

    Registers a listener to handle events which occur after a new report is generated. Handle the CanReportException event to cancel sending a report. In this case, the generated report is not posted to the service and the BeforeReportException is not raised.

    import com.devexpress.logify.alert.android.LogifyAlert;
    import com.devexpress.logify.alert.core.events.CanReportExceptionLogifyEvent;
    import com.devexpress.logify.alert.core.events.LogifyEventListener;
                            
    // Register an event listener with the implementation below.
    LogifyAlert.getInstance().addCanReportExceptionListener(new CanReportExceptionEventListener());
    // ...
    // Implement an event listner.
    private class CanReportExceptionEventListener implements LogifyEventListener {
        public void handle(CanReportExceptionLogifyEvent event) {
            // ...
            event.setCancel(true);
        }
    }

  • removeAfterReportExceptionListener

    void removeAfterReportExceptionListener(LogifyEventListener<AfterReportExceptionLogifyEvent> LogifyEventListener)

    Removes a listener the addAfterReportExceptionListener method registered.

  • removeBeforeReportExceptionListener

    void removeBeforeReportExceptionListener(LogifyEventListener<BeforeReportExceptionLogifyEvent> LogifyEventListener)

    Removes a listener the addBeforeReportExceptionListener method registered.

  • removeCanReportExceptionListener

    void removeCanReportExceptionListener(LogifyEventListener<CanReportExceptionLogifyEvent> LogifyEventListener)

    Removes a listener the addCanReportExceptionListener method registered.

Set Up Client using a Properties File

You can set up the Logify Alert client for Android applications in the logify.properties file. Logify Alert reads this file if you pass your application context to the client using the setContext method.
The following configuration parameters are available:

apiKey=YOUR_API_KEY
appName=YOUR_APP_NAME
appVersion=YOUR_APP_VERSION
userId=YOUR_USER_ID
customData=NAME_1:VALUE_1,NAME_2:VALUE_2,NAME_3:VALUE_3
tags=TAG_1:VALUE_1,TAG_2:VALUE_2

Note: Properties assigned in code override values specified in the logify.properties file.

Terms of use Copyright © 2016-2019 Developer Express Inc.