The Pixel's new 'HiLight' reminds me of the golden days of Android phones
Back to Tutorials
techTutorialbeginner

The Pixel's new 'HiLight' reminds me of the golden days of Android phones

August 16, 202638 views4 min read

Learn to create Android notifications with LED effects similar to Google's HiLight feature on Pixel phones. This beginner-friendly tutorial teaches you how to implement notification channels and LED visual effects in Android apps.

Introduction

In this tutorial, you'll learn how to create a simple Android notification LED effect using Android Studio. This tutorial is inspired by Google's new 'HiLight' feature on Pixel 11 Pro phones that brings back the classic notification LED design from early Android phones. We'll build a basic Android app that demonstrates how LED notifications work, giving you hands-on experience with Android's notification system and visual effects.

Prerequisites

Before starting this tutorial, you'll need:

  • Android Studio installed on your computer
  • Basic understanding of Android development concepts
  • Android SDK with API level 21 or higher
  • A physical Android device or Android emulator

Step-by-Step Instructions

Step 1: Create a New Android Project

1.1 Open Android Studio and Start a New Project

Launch Android Studio and select 'Create New Project'. Choose 'Empty Activity' as your template and click 'Next'.

1.2 Configure Your Project

Set the project name to 'LEDNotificationDemo', select 'Java' as the language, and set the minimum SDK to API 21 (Android 5.0). Click 'Finish' to create the project.

Step 2: Add Notification Permissions

2.1 Add Permissions to AndroidManifest.xml

Open the AndroidManifest.xml file and add the following permission:

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

Why we add this: The POST_NOTIFICATIONS permission is required for apps to send notifications to users, which is essential for LED effects.

Step 3: Create Notification Channels

3.1 Create a NotificationHelper Class

Create a new Java class named NotificationHelper in your app's package:

public class NotificationHelper {
    private static final String CHANNEL_ID = "led_notification_channel";
    private static final String CHANNEL_NAME = "LED Notifications";
    private static final String CHANNEL_DESCRIPTION = "Channel for LED notification effects";

    public static void createNotificationChannel(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(
                CHANNEL_ID,
                CHANNEL_NAME,
                NotificationManager.IMPORTANCE_HIGH
            );
            channel.setDescription(CHANNEL_DESCRIPTION);
            channel.enableLights(true);
            channel.setLightColor(Color.BLUE);
            channel.enableVibration(true);
            channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 100});
            
            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }
}

3.2 Call the Notification Channel Creation

In your MainActivity.java, add this to the onCreate method:

NotificationHelper.createNotificationChannel(this);

Why we create channels: Android 8.0+ requires notification channels to manage notifications, including LED effects. This ensures your LED notifications work properly.

Step 4: Create the LED Notification

4.1 Add a Button to Trigger Notifications

In your activity_main.xml, add a button:

<Button
    android:id="@+id/buttonShowNotification"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Show LED Notification"
    android:layout_centerInParent="true" />

4.2 Implement Notification Logic

In your MainActivity.java, add the following code:

private void showLEDNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationHelper.CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle("LED Notification Demo")
        .setContentText("This notification has LED effects!")
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setAutoCancel(true)
        .setLights(Color.BLUE, 1000, 1000);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(1, builder.build());
}

4.3 Set Up Button Click Listener

Add this to your onCreate method:

Button button = findViewById(R.id.buttonShowNotification);
button.setOnClickListener(v -> showLEDNotification());

Why we use setLights: This method directly controls the LED behavior, setting the color and timing for the LED flash, mimicking the classic Android notification LED effects.

Step 5: Test Your LED Notification

5.1 Build and Run the App

Connect your Android device or start an emulator, then click the 'Run' button in Android Studio.

5.2 Test the LED Effect

Click the 'Show LED Notification' button. You should see a notification appear with a blue LED flash on your device's notification LED.

Why we test this way: Testing directly on a device with a notification LED (like older Android phones or Pixel devices) will show you the actual LED behavior, similar to the HiLight feature.

Step 6: Customize Your LED Effect

6.1 Modify LED Color and Timing

Change the color and timing in the setLights method:

.setLights(Color.RED, 500, 500); // Red LED, 500ms on, 500ms off

Try different colors like Color.GREEN, Color.YELLOW, or Color.CYAN.

6.2 Experiment with Timing Patterns

Modify the timing to create different LED patterns:

.setLights(Color.BLUE, 200, 300); // 200ms on, 300ms off

Why we customize: Different LED patterns and colors help you understand how the visual notification system works and how to create various notification effects.

Summary

In this tutorial, you've learned how to create Android notifications with LED effects similar to Google's HiLight feature on Pixel phones. You've created a complete Android app that demonstrates:

  • Setting up notification channels for Android 8.0+
  • Implementing LED notification effects using setLights()
  • Testing LED notifications on physical devices
  • Customizing LED colors and timing patterns

This hands-on experience gives you practical knowledge of Android's notification system and how LED visual effects work in modern Android development. The skills you've learned can be applied to create more sophisticated notification experiences in your own Android apps.

Source: ZDNet AI

Related Articles