Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Target SDK Version 26に上げる時につまづいたこと
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
katsuki-nakatani
September 19, 2017
Technology
2.9k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Target SDK Version 26に上げる時につまづいたこと
Android Oreo Migration (Notification Channel,Background Limits) from GDG Kobe
katsuki-nakatani
September 19, 2017
More Decks by katsuki-nakatani
See All by katsuki-nakatani
Android 10 対応 Tips
katsukinakatani
0
130
InAppUpdate実装&InAppBillingClientVer2.0実装例
katsukinakatani
0
630
AndroidJetpack概要 &旧AACの紹介
katsukinakatani
0
730
ViewModel使ってますか?
katsukinakatani
0
340
デフォルトアプリとパーミッション
katsukinakatani
0
230
Whats new android wear (umeda.apk #3 LT)
katsukinakatani
1
520
Android 7.1.1 AppShortcuts setup(DevfestKansai Lightning Talk)
katsukinakatani
1
730
Firebase Authentication & Firebase Realtime Database setup
katsukinakatani
2
920
Firebase Setup for Android Studio2.2
katsukinakatani
1
640
Other Decks in Technology
See All in Technology
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
1.3k
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
180
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
190
Getting Started with Google Antigravity
glaforge
0
320
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
360
専門領域のAIをどう評価するか
bengo4com
2
290
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
200
AI時代のPRレビューにどう向き合うか?
kairim0
1
240
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
200
価値について
gree_tech
PRO
0
100
React改造してみた
tsukina_7mochi
0
120
Featured
See All Featured
Visualization
eitanlees
153
17k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
For a Future-Friendly Web
brad_frost
184
10k
From π to Pie charts
rasagy
1
400
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Fireside Chat
paigeccino
43
4.1k
Being A Developer After 40
akosma
92
590k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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!!