enoent

Compat libraries incompatibilities

Compat libraries are great. They allow us to work with newest Android APIs, without thinking (much) about your minimum API level. Instead of thousands of devices, you can reach billions. With nearly no changes in your code.

But sometimes, they’re not so great…

Android Things: first look

What is Android Things?

Android Things is an alternative Android version, announced at Google I/O 2015, and released as a first developer preview in December 2016. Its purpose is to develop embedded IoT devices, with a known and widely documented Android ecosystem basis.

It’s currently running on three different boards: the Intel Edison, the NXP Pico i.MX6UL, and the Raspberry Pi 3. Some higher-end boards are coming soon.

On the SDK side, Android Things comes with a specific support library to ease low-level hardware usage. It consists in two parts: the Peripheral I/O API, which supports GPIO, PWM, I2C, SPI and UART, and the User Driver API, which allows a developer to write a hardware-specific, high-level driver, to ease hardware reusability by injecting events into the Android framework. Other applications can in turn use those events without having to interact with the hardware directly.

There’s a down side: the bundled Android is not as complete as the one you can find on a phone. Most of the standard applications aren’t installed (Calendar, Phone…), and standard content providers are absent too (MediaProvider, Dictionary…).

Android Things supports displays, with the default Android UI toolkit. However, the display is a little bit different from what you’re used to see on an Android device: there’s no notification bar, navigation bar or anything, the running application will use the full display. That is, if it uses it at all: displays are purely optional.

Use Apache HTTP Client on Android SDK 23

With the Android M SDK (API 23), Google removed the Apache HTTP Client library. It was deprecated since API 22, and Google recommanded to use HttpURLConnection instead since API 9. While the classes are still bundled in Android 6 ROMs, it won’t be long until we see them completely go away.

Some applications are still relying on this library, and need to be updated to use the SDK 23, without having time/budget/whatever required to switch from HTTP Client. While I strongly recommend you to still take time to move to something else (there are many high-level libraries, like OkHttp or Ion, or you can use HttpURLConnection to keep a low-level access), there is a way to use the Apache library while using the SDK 23.

Share code across multiple platforms

When writing an application, you probably want it to run on most platforms possible. Having a game on Android is great, but what about this weird friend with his iPhone? It would be nice to be able to play with him. Of course there are cross-platforms technologies like Cordova or Titanium. But sadly, you can’t achieve both a perfect user experience and great performances with this kind of tools. And even if you could: what about reusing code on the back-end? We need to share some code.

RecyclerView basics

Introduction to RecyclerView

RecyclerView has been introduced with Android 5, in the support-v7 package. It allows to display a collection of items in an arbitrary disposition (think of a ListView, but much more flexible). As the name of the support package indicates, it’s available from the API level 7 (Android 2.1).

Its name comes from the way it works: when an item is hidden, instead of being destroyed and a new one being created for each newly displayed item, hidden ones are recycled: they are reused, with new data bound on them.

Hosting different kinds of apps on nginx

Engine what?

Nginx (engine-x) is a web server and reverse proxy for web and mail protocols (HTTP, HTTPS, SMTP, POP3 and IMAP). It has been first released in 2004, and its usage keeps growing ever since (according to Netcraft, it was hosting 14.47% of active sites in August 2014).

It’s capable of hosting many kinds of applications:

  • static HTML pages
  • PHP, using PHP-FPM
  • Ruby on Rails and any kind of Rack-based Ruby application, using Phusion Passenger
  • proxying requests to another webserver (e.g. a software launching its own web server, like Kodi)

Using an API - Trakt.tv example

A lot of websites are generating data which could be really useful outside of a web browser. Having the weather shown on your smartphone’s lock-screen, the delay until your next bus… How can we use this from an application?

This article will explain what’s behind these hidden data flows, and how to use them. For this purpose, I’ll use Trakt.tv as an example. If you don’t know it: Trakt allows you to manage your movie/TV series library, keep track of watch progress, your ratings, comments… and see those of other people.

Some code will show how to send such requests. It will be written in Ruby.

Compile FFmpeg for Android

When you have to manipulate audio or video on Android, being used to open-source software, you have a single name which comes directly to you: FFmpeg. However, FFmpeg is a C software, meant to be used as an executable, and not officially supporting Android.

There are a lot of partial and/or out-of-date how-to out there on how to get FFmpeg running on Android, like halfninja’s build. However, I needed to use FFmpeg concat demuxer, introduced in FFmpeg 1.1. Most builds target 0.9. There’s a ton of questions on StackOverflow about getting newer FFmpeg releases working on Android. So, here’s a full explanation to get FFmpeg 2.2.3 “Muybridge” working on Android. I’ll describe the steps for Linux, but everything is pretty standard shell and should work on any decent OS.

Android: display a Dialog from an AppWidget

Issue

When you want to display a dialog, you don’t only need a context, you need an activity context. From an activity, displaying a dialog is pretty straightforward:

Display a dialog from an activity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
new AlertDialog.Builder(MyActivity.this)
    .setTitle("Dialog title")
    .setMessage("Dialog message")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Handle a positive answer
        }
    })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Handle a negative answer
        }
    })
    .setIcon(R.drawable.ic_dialog_alert)
    .show();

Okay, that’s a pretty usual code sample. But what about displaying it from an app-widget?