Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Target SDK Version 26に上げる時につまづいたこと
Search
katsuki-nakatani
September 19, 2017
Technology
3
2.8k
Target SDK Version 26に上げる時につまづいたこと
Android Oreo Migration (Notification Channel,Background Limits) from GDG Kobe
katsuki-nakatani
September 19, 2017
Tweet
Share
More Decks by katsuki-nakatani
See All by katsuki-nakatani
Android 10 対応 Tips
katsukinakatani
0
94
InAppUpdate実装&InAppBillingClientVer2.0実装例
katsukinakatani
0
560
AndroidJetpack概要 &旧AACの紹介
katsukinakatani
0
660
ViewModel使ってますか?
katsukinakatani
0
310
デフォルトアプリとパーミッション
katsukinakatani
0
200
Whats new android wear (umeda.apk #3 LT)
katsukinakatani
1
490
Android 7.1.1 AppShortcuts setup(DevfestKansai Lightning Talk)
katsukinakatani
1
690
Firebase Authentication & Firebase Realtime Database setup
katsukinakatani
2
870
Firebase Setup for Android Studio2.2
katsukinakatani
1
620
Other Decks in Technology
See All in Technology
AWSの最新サービスでAIエージェント構築に楽しく入門しよう
minorun365
PRO
8
390
Amazon Inspector コードセキュリティで手軽に実現するシフトレフト
maimyyym
0
130
Serverless Meetup #21
yoshidashingo
1
130
AIと描く、未来のBacklog 〜プロジェクト管理の次の10年を想像し、創造するセッション〜
hrm_o25
0
110
Eval-Centric AI: Agent 開発におけるベストプラクティスの探求
asei
0
140
Amazon Q Developerを活用したアーキテクチャのリファクタリング
k1nakayama
2
220
Amazon Qで2Dゲームを作成してみた
siromi
0
160
S3 Glacier のデータを Athena からクエリしようとしたらどうなるのか/try-to-query-s3-glacier-from-athena
emiki
0
240
[OCI Technical Deep Dive] OCIで生成AIを活用するためのソリューション解説(2025年8月5日開催)
oracle4engineer
PRO
0
120
20250807_Kiroと私の反省会
riz3f7
0
260
いま、あらためて考えてみるアカウント管理 with IaC / Account management with IaC
kohbis
1
220
データモデリング通り #2オンライン勉強会 ~方法論の話をしよう~
datayokocho
0
190
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Applications with DynamoDB
mza
96
6.6k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Six Lessons from altMBA
skipperchong
28
4k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Bash Introduction
62gerente
614
210k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
460
How STYLIGHT went responsive
nonsquared
100
5.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
283
13k
Code Reviewing Like a Champion
maltzj
525
40k
Transcript
Target SDK Version 26に上げた時に躓いたこと 2017/9/18 Android Oreo with Kotlin&Android Studio
3.0勉強会
Speaker 中谷 克紀 仕事 Enterprise Server Engineer GDG 神戸スタッフ
Theme 本日の勉強会のテーマは3つあります Android Oreo(8.0) Kotlin Android Studio
OSバージョンのおさらい API Level Android バージョン 備考 4 1.6 Xperiaが登場 5 2.0
6 2.0.1 7 2.1 8 2.2 JITコンパイラで高速化 9 2.3.0 ~ 2.3.2 10 2.3.3 ~ 2.3.7 14 4.0.1 ~ 4.0.2 HoloテーマやFragmentの追加。(Honeycombで追加されていた?知らない子ですねぇ) 15 4.0.3 ~ 4.0.4 16 4.1.0 ~ 4.1.2 Google NowやGCM(旧C2DM)が登場 17 4.2.0 ~ 4.2.2
OSバージョンのおさらい API Level Android バージョン 備考 18 4.3.0 ~ 4.3.1 19
4.4.0 ~ 4.4.4 Daydream? VRですか? 20 4.4w 初のAndroid Wear用バージョン 21 5.0.0 ~ 5.0.2 Material Designの登場 22 5.1 5.0のマイナーバージョンアップ 23 6.0.0 ~ 6.0.1 Runtime Permissionの登場 24 7.0.0 マルチタスク 25 7.1.0 ~ 7.1.2 7.0のマイナーバージョンアップ
API Level 26 Android Oreoの登場
Android Oreoでの新しい機能 ・Picture in Picture(P in P) ・Notification Channel ・Autofill
Framework ・Background Limits ・Autosize Textview ・Download Fonts https://developers-jp.googleblog.com/2017/09/introducing-android-8-oreo.html ・Adaptive Icon more... https://developers-jp.googleblog.com/2017/09/introducing-android-8-oreo.html
API Level上げてみました アプリの機能 ・ACやUSBプラグなどを接続・切断したのをトリガーに 通知バーに通知を行いLEDを充電量に合わせて光らせる
API Level上げてみました compileSdkVersion 26 defaultConfig { applicationId "com.miruker.nexusbatteryled" minSdkVersion 23
targetSdkVersion 26 versionCode 15 versionName "1.9.3" signingConfig signingConfigs.debugKey }
結果 通知が表示されなくなってしまった 端末起動時にアプリがクラッシュするようになった
Notificationの仕組みが変わりました
バッジがつくようになりました
通知の実装を変えないと、通知が 表示されなくなります
何が変わったの? Android 8.0より前 通知については、Notification単位で通知の重要度、LED、Vibe等を設定していた Android 8.0 通知チャンネルという概念が追加。通知チャンネルで通知の重要度、LED、Vibe等を設定する Notificationを通知チャンネルへ発行することで、通知チャンネルの設定に従い端末に通知される
Notification before Android 7.x var builder = NotificationCompat.Builder(this).apply{ setSmallIcon(R.drawable.notification_icon) setContentTitle("My
notification") setLights(Color.BLUE,100,300) setContentText("Hello World!") } NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mId, builder.build()); Notificationを作成 マネージャに渡して通知
Notification after Android 8.0 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ var manager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager var channel = NotificationChannel("channel_1",getString(R.string.channel_1), NotificationManager.IMPORTANCE_HIGH) .apply { lightColor = Color.RED lockscreenVisibility = Notification.VISIBILITY_PUBLIC enableLights(true) } manager.createNotificationChannel(channel) Notification Channelを作成 var manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager var notification = NotificationCompat.Builder(this,"channel_1").apply { setSmallIcon(R.drawable.ic_stat_name) setContentText("チャンネル1通知です ") }.build() manager.notify(1,notification) Channelに通知を投稿
後方互換性 var manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager var notification =
NotificationCompat.Builder(this,"channel_2").apply{ setSmallIcon(R.drawable.ic_stat_name) setLights(Color.BLUE,1000,10) setContentText("チャンネル2通知です") }.build() manager.notify(2,notification) NotificationCompatを利用して、通知を発行します 赤文字の箇所で、Oreo以降の投稿するチャンネルIDを記述します 青文字の箇所は、従来通りNougat以前の通知をサポートするために記述します 元からCompatを利用している場合は、Builderを生成する第二引数にChannelIDを追加するだけでOKです ※Oreoで通知を発行した場合、NotificationでLEDを指定してもChannel側で指定したLEDカラーが優先されます
Channel設定はユーザーが変更できる
どういうメリットが有るの? 開発者 通知の選択を行わせる設定画面を作らなくて良くなった 利用者 必要な通知だけを自分好みにカスタマイズできるように 通知がうざいので、アプリごと通知を削除される可能性が低減される
ユーザのチャンネル設定を知りたい var manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager var channel =
manager.getNotificationChannel("channel_1") NotificationManagerから取得することが出来ます 通知チャンネルの削除も、 NotificationManagerから行います
Compatを使えないケースの場合は NotificationCompatに無いメソッドを利用している場合はバージョン分岐で書きましょう setSmallIcon(Icon icon)はBackportされていない。。。
次の対応 通知が表示されるようになりました 端末起動時にアプリがクラッシュするようになった
Background Serviceの実行に 制限が入りました
Background Limits https://developer.android.com/about/versions/oreo/background.html
Backgroundの制限は大きく分けて2つ https://developer.android.com/about/versions/oreo/background.html Background Execution Limits バックグラウンドの実行を制限するもの Background Location Limits バックグラウンドので位置情報の取得を制限するもの
Broadcastの制限 https://developer.android.com/guide/components/broadcast-exceptions.html ManifestでBroadcastReceiverを登録することができなくなりました ただし一部のレシーバは例外的にmanifestで利用が可能です 例えば、ACTION_BOOT_COMPLETEDは今まで通り利用可能なので、端末が起動した後にジョブを実行するなどは 従来通り可能です。 引き続きBroadcastを受け取る場合は「Context.registerService()」を使って、実行時にレシーバーを登録します
BackgroundService実行時の制限
BackgroundService実行時の制限
今回のクラッシュの原因 システム起動時(ACTION_BOOT_COMPLETED)時にサービスを実行して、パワープラグのON、OFF取得用レシーバ登録処理など を実行していた この時、画面も表示されない(可視アクティビティもない)し、フォアグラウンドサービスを使う等のその他の条件にも該当せず。 このようにBootCompletedでサービスを実行して何か処理をするというケースは真っ先に該当します
Oreoでバックグラウンドサービスを動かす Start Service before Android 7.x context.startService(Intent(context, BatteryCheckerService::class.java)) Start Service
after Android 8.0 context.startForegroundService(Intent(context, BatteryCheckerService::class.java))
これだけではダメ Service Notification before Android 7.x 特にサービス側では明示的に何もする必要がありません Service after Android
8.0(例:IntentServiceを使う場合) override fun onHandleIntent(intent: Intent?) { startForeground(R.string.app_name, NotificationCompat.Builder(applicationContext).build()) //サービス内の処理等 } サービスが起動後、直ちに(5秒以内)にNotificationを発行してください サービスが動作していることがユーザーに明示(通知)されます
もちろんこれもダメ startForegroundService()を発行してから5秒以内にサービス(処理)が終了するから手当しない →サービスが終了(stopService)でANRになります
罠 https://developer.android.com/about/versions/oreo/background.html DeveloperPreview初期の頃は、NotificationManagerにstartServiceInForeground()が生えていて、 これを使うようになっていたのですが、最終的にContext.startForegroundService()になっています
Tips Context.startForegroundService()はAPILevel26からなので、バージョンを見て分岐してあげましょう
Adaptive Icon Android Studioから生成できるので、 こちらを利用して作るのがオススメです
まとめ Android Oreoへバージョンを上げることで、他にも影響が出る部分はありますが、 今回変更になった、「Notification Channel」「Background LImits」への対応を紹介しました 皆様のアプリも、いち早くTargetSDKVersionを26に出来るようにご参考になれば幸いです!
おしまい Try TargetSDKVersion 26!!