CN

loading
Android Tips: How to Prevent EditText from Automatically Getting Focus

Reviewed 2026-10-13: This technique applies to traditional Android View layouts. The focus attributes have been available since API 1 and remain supported. Input focus and keyboard visibility are separate states, so adding the attributes does not guarantee that the keyboard stays hidden in every situation.

In Android development, using EditText is very common. However, sometimes EditText automatically grabs focus when entering a page, causing the soft keyboard to pop up immediately. While this is convenient in some cases, most of the time we prefer the keyboard to appear only when the user explicitly clicks on the EditText.

Android Tips Round-Up, Part 2

For the second Chinese post in this series, I translated Dan Lew’s Android Tips Round-Up. As in the first part, I’ve added notes from using some of these tools and filled in explanations where I thought they would help. If a few of the APIs are new to you, I hope the list comes in handy. The API updates are noted below.

Reviewed 2026-10-13: This 2014 list covers View and system utility APIs. Activity.onBackPressed() was deprecated in API 33, and text layout has a Builder API from API 23. The notes below add replacements and correct the explanations of alarms, application memory, and screen density.

Android Tips Round-Up, Part 1

Reviewed 2026-10-13: This 2014 list focuses on Android’s View system. Most APIs remain valid. The old Html.fromHtml(String) overload was deprecated in API 24; the notes below add its replacement and correct the descriptions of cache directories, layout inflation, and reverse playback.

For the first Chinese post in this series, I translated Dan Lew’s Android Tips Round-Up. You may already know some of these small SDK tools; I’m writing them down in case a few are new to you. It isn’t a word-for-word translation. I use some of these classes myself, so I’ve added my own notes and explanations where I thought they would help. This English edition includes the API updates below.

Android Tools - Log2File

Updated 2026-10-13: The 2014 implementation wrote directly under the external-storage root, which is outdated. Android 10 (API 29) introduced scoped storage; Android 11 (API 30) ignores requestLegacyExternalStorage for apps targeting API 30 or higher. The replacement below uses app-internal storage, requires Android 4.4 (API 19) or later, and needs no storage permission. See Android 11 storage changes.

Log2File records logs explicitly supplied by an Android application to a file. It is useful when:

  1. A computer cannot be connected for debugging, for example because USB OTG occupies the port.
  2. Logs are difficult to capture in real time.
  3. An intermittent bug requires a record of the operations preceding it.
  4. I’ll leave the other uses to your imagination.

It saves only the content passed to w(); it does not automatically capture system logcat. Use the Logcat tools for system logging.

0. Introduction

This article originally appeared on my CSDN blog before moving here. The original GitHub source URL returned 404 during this update, so the replacement implementation is included below.

Android Service: Building Your Own Notification Center (2) - Accessibility Service in Practice

Updated 2026-10-13: This article records the historical approach of observing notifications through accessibility events before Android 4.3. That approach is outdated for a general notification center. Android 4.3 (API 18) introduced NotificationListenerService; section 4 adds a minimal listener for Android 7.0 (API 24) and later. The legacy examples explain the earlier implementation and do not provide a complete notification list.

1. Accessibility Service in Practice

The previous article introduced accessibility services and their basic configuration. This article follows the original implementation of a simple notification center. Android’s system notification UI displays notifications from apps and system components, such as missed calls, screenshots, weather, and news updates. Before Android 4.3, ordinary third-party apps did not have a public API to query the active notification list. Accessibility events offered a limited way to observe notifications; Android 4.3 added the dedicated NotificationListenerService.getActiveNotifications() API.

Ubuntu: Adb Command Cannot Find Device

This post dates from 2014, when I was using a Nokia X and an old Android SDK. The udev and user-group instructions were updated for Ubuntu 24.04 LTS on 2026-10-13. The old SYSFS rule and Upstart restart procedure no longer apply; the adb_usb.ini workaround remains at the end as a historical note.

1. Problem Overview

Recently, while developing for a Nokia project, I encountered the following issue:

When I plugged in a Nokia X, the computer did not respond at all—it wasn’t recognized. My colleague’s Windows machine also failed to detect it. After searching Google for a long time, I finally found a solution. Since I didn’t record it originally and later forgot how to configure it when helping someone else, I decided to document it here for everyone.

2. Solution

Enable USB debugging on the device and use a cable that supports data transfer. Check the selected Platform-Tools version with adb version, then inspect the connection using adb devices -l.

  • Empty list: check the cable, port, USB debugging setting, and whether the host enumerates the device.
  • no permissions: check Linux udev rules and the current user’s groups.
  • unauthorized: ADB has found the device; unlock it and accept the RSA debugging prompt.
  • offline: the device is not responding normally to ADB; reconnect it or restart the ADB server and inspect the state again.

USB enumeration, host permissions, and device authorization are separate checks. See the ADB reference and hardware-device setup guide.

Android Service: Building Your Own Notification Center (1) - Introduction to Accessibility Service

1. Introduction to Accessibility Service

Updated 2026-10-13: This article was originally written in 2014 and covers accessibility service configuration available from Android 4.0 (API 14). Accessibility services remain supported, but using them as a general notification-center API is outdated. Android 4.3 (API 18) introduced NotificationListenerService for that purpose. The examples below correct service declarations and explain the node-recycling change in Android 13 (API 33).

Accessibility services help people with disabilities, or people temporarily unable to interact with a device, use applications. They can read interface text aloud or provide haptic feedback. This section covers service creation, event handling, and inspecting accessibility nodes.

The system binds an AccessibilityService after the user enables it; it is not started like an ordinary background task service. The examples give you a service skeleton and a few methods. To use them in your app, you’ll still need to add text-to-speech, a settings interface, and application resources. See the service lifecycle and configuration reference.