Android Oプレビュー1の概要:主な変更点と新機能の紹介

Android O

Googleは日本時間で3月22日、Androidの最新バージョンアンドロイドO開発者プレビュー1を公開しました。まだ開発者向けプレビューであるため、機能が不安定だったり正式な名前が未定だったりします。Androidはこれまでアルファベット順に名前をつけているため、次のバージョンのAndroidは、アルファベットOで始まることが予想されていました。今回公開されたバージョンも予想通りアンドロイドOとして公開されています。正式名称はオレオという噂もありますが、正式な発表はなにもありません。

以前KのときのAndroidの名前がキーライムパイという噂がありましたが、正式な名前が公開されるとキーライムパイではなくキットカットだったことを覚えている方も多いと思います。

プレビューのスケジュール

スケジュール画像

Androidの開発者向けプレビュー1は、3月中旬に公開されました。その後は、開発者プレビュー2が5月、開発者向けプレビュー3が6月、開発者プレビュー4が7月、正式版のリリースは第3四半期を予定しています。時期的に見ると、開発者向けプレビュー2の公開は、Googleの開発者イベントであるGoogle I/Oの時になる可能性が高いでしょう。

プレビュー3で正式にAPIが確定し、以後のプレビュー4と正式版では機能の安定化が行われます。

##互換性チェック

次の項目は、Android Oで大きく変化した部分です。アプリの互換性のために、ぜひ事前に確認してください。

  • バックグラウンドアプリは時間当たり一定回数以上の位置情報を受け取ることができません。
  • net.hostnameを参照することはできなくなります。
  • connect(InetAddress、int)の呼び出しが失敗した後、send(DatagramPacket)を呼び出すと、SocketExceptionが発生します。
  • AbstractCollection.removeAll(null)AbstractCollection.retainAll(null)はNullPointerExceptionをスローします。
  • Currency.getDisplayName(null)もNullPointerExceptionをスローします。
  • net.dns1 net.dns2net.dns3 net.dns4プロパティを参照することはできなくなります。
  • ネイティブライブラリは、書き込み可能かつ実行可能なセグメントをロードすることは禁止されます。
  • ELFヘッダと部分をより厳密にチェックします。
  • アンドロイドOをターゲットとするアプリは、通知チャネルに対応する必要があります。
  • Collections.sort()List.sort()を呼び出すように変更されたため、イテレート中のリストにCollections.sort()を適用するとConcurrentModificationExceptionがスローされます。

AndroidのOの追加機能

AndroidのOには多くの機能が追加される予定です。その中で主な機能のいくつかを見ていきましょう。

記事の更新情報を受け取る

###通知チャネル

アンドロイドOをターゲットとするアプリは、通知チャネルの機能を利用することができます。個々の通知の重要度は廃止され、チャネルごとに重要度を設定することができます。チャンネルについて、ユーザーは、重要度、音、光、振動、ロックスクリーンに表示するかどうかなどを設定することができます。

チャンネルは、次のように簡単に作成することができます。


NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// The id of the channel.
String id = "my_channel_01";
// The user visible name of the channel.
CharSequence name = getString(R.string.channel_name);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
// Configure the notification channel.
mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mNotificationManager.createNotificationChannel(mChannel);

チャネルに通知を送信することも簡単です。


mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated.
int notifyID = 1;
// The id of the channel.
String CHANNEL_ID = "my_channel_01";
// Create a notification and set the notification channel.
Notification notification = new Notification.Builder(MainActivity.this)
        .setContentTitle("New Message")
        .setContentText("You've received new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setChannel(CHANNEL_ID)
        .build();
// Issue the notification.
mNotificationManager.notify(id, notification);

通知グループの設定

###ピクチャーインピクチャー(Picture-in-Picture)

ピクチャーインピクチャーは新しい機能ではありません。Android TVでは以前からピクチャーインピクチャー(PIP)を使うことができましたが、それ以外の端末では画面分割モードを使用する必要がありました。

画面分割モード

ピクチャーインピクチャー

TV機器でピクチャーインピクチャーが実行された画面です。

PIPのように複数ウインドウを有効にした状態での動作をサポートするためには、動画の再生のような機能ではonPause()onResume()で再生を停止/再開するのではなく、onStop()onStart()で対応する必要があります。

###フォント

フォントファイルとフォントファミリーリソースをリソースのfontフォルダーに追加すると、レイアウトXMLでフォントを指定することが可能になります。

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font
        android:fontStyle="normal"
        android:fontWeight="400"
        android:font="@font/lobster_regular" />
    <font
        android:fontStyle="italic"
        android:fontWeight="400"
        android:font="@font/lobster_italic" />
</font-family>

上記のようにフォントリソースファイルを作成してから、次のように適用します。

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/lobster"/>
        

###アダプティブアイコン

アダプティブアイコン

端末に応じてアイコンの形状を丸や四角に自動的に切り替えます。

<application
    // …
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    // …
>
</application>


<adaptive-icon>
    <background android:drawable="@color/ic_background"/>
    <foreground android:drawable="@mipmap/ic_foreground"/>
</adaptive-icon>

フォアグラウンドとバックグラウンドを指定していますが、これらの画像を重ねた上で適切にマスクして表示してくれます。

注: 公式ドキュメントには adaptive-iconではなくmaskable-iconを使用するように書かれていますが、issue36535386にあるように、実際にはadaptive-iconタグを使用しないと正しくアイコンが表示されません。

##より進む

GoogleのAndroidプレビューページで、ここで取り上げた機能以外についても説明されています。

About the content

This content has been published here with the express permission of the author.


Leonardo Kim

Leonardo YongUk Kim is a software developer with extensive experience in mobile and embedded projects, including: several WIPI modules, iOS projects, a scene graph engine for Android, an Android tablet, a client utility for black boxes, and some mini games using Cocos2d-x. He has also developed many open source projects.

Additionally, Leonardo has been an organizer of GDG Korea Android for the last several years. To date, he has organized conferences, codelabs, hackathons, and meetups.

4 design patterns for a RESTless mobile integration »

close