Send push notifications to your mobile device or browser using Java

When developing software, it’s crucial to have a means of tracking significant events and receiving timely notifications. LogHive offers a simple solution for tracking important events and receiving real-time alerts on your desktop, phone, and smartwatch.

All you need to do is send an HTTP request to our API with any supplementary data, and LogHive handles the rest.

How it works in Java

LogHive provides a simple REST API that you can use to push events and errors to the LogHive service. You can organize your events into projects and groups to keep them organized and easily searchable. Once an event is pushed to LogHive, it is processed and can be viewed in the event stream or dashboard.

With just a few lines of Java-code, you can start pushing events to LogHive and receiving push notifications for your application’s events and errors.

import java.util.Map;

public class HttpClientExample {

    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .header("Content-Type", "application/json")
                .header("Authorization", "ApiKey: your-api-key")
                .POST(BodyPublishers.ofString("{\"project\":\"yourprojectname\", \"group\":\"Payments\",\"event\":\"Payment received\",\"description\":\"your-description\",\"notify\":false}"))

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

        System.out.println("Status code: " + response.statusCode());
        System.out.println("Response headers: " + response.headers().map());
        System.out.println("Response body: " + response.body());

If an error occurs while creating an event, you will receive an Error object in return.

{'StatusCode': 400, 'Message': 'missing group name'}

You can receive your API-Key here: API-Key.

Receive Push Notifications

To receive push notifications, you simply need to install the LogHive Android app (Playstore) or use LogHive through the web application and allow notifications.

Add an element to your project dashboard

In addition to push notifications, LogHive allows you to display captured events in a dashboard with various elements. With just a few clicks, you can display the events already pushed in the dashboard.

In conclusion, it is essential to have a reliable means of tracking and monitoring events when developing software. LogHive offers an easy-to-use solution that allows users to track important events and receive real-time notifications on multiple devices.

Latest Posts