SlideShare a Scribd company logo
1 of 45
Download to read offline
Migrating to Android 8.0
presented by
Daniel Deng
2017/11/30
This presentation is provided on a strictly private and confidential basis for information purposes only.
Daniel Deng
Android Developer
FB: Daniel Deng
LinkedIn: daniel-deng-97742454
This presentation is provided on a strictly private and confidential basis for information purposes only.
今天不會介紹 Android Oreo 的新功能
This presentation is provided on a strictly private and confidential basis for information purposes only.
也不會逐一說明所有的 API 變更
詳情請自行參閱 https://developer.android.com/about/versions/oreo/android-8.0-changes.html
This presentation is provided on a strictly private and confidential basis for information purposes only.
那今天要介紹什麼 ?
This presentation is provided on a strictly private and confidential basis for information purposes only.
我們實際將 targetSdkVersion 升至
Android 8.0 遇到的問題
This presentation is provided on a strictly private and confidential basis for information purposes only.
Outline
• 關於版本
• 背景執行限制
• Notification Channel
• Alert Windows
• GCM Service
• AudioAttributes
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (1/5)
• minSdkVersion
• compileSdkVersion
• targetSdkVersion
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (2/5)
• minSdkVersion
• 允許安裝的最低版本要求
• 會相依使用的 Library 中的 minSdkVersion
• 參考 Android OS 分佈統計決定
2017/11/9 Android OS 版本占比
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (3/5)
• compileSdkVersion
• 使用哪個 Android SDK 版本編譯
• 編譯後可能會出現錯誤或警告
• 會出現低於此版本的棄用 API 警告
• 至少需和使用的 Support Library 同個版本
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (4/5)
• targetSdkVersion
• 向下兼容至哪個版本
• 會套用該版本的行為變化
• 一定要事先測試
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (5/5)
Q: Android 6.0 (API Level 23) 調整了權限授權行為,小明的 App 使
用了列為危險權限的「READ_CONTACTS」。
他的 App compileSdkVersion 為 23,targetSdkVersion 為 21
請問小明的 App 可以不做 runtime permission 的調整在 Android 6.0
的手機上執行嗎?
This presentation is provided on a strictly private and confidential basis for information purposes only.
關於版本 (5/5)
Q: Android 6.0 (API Level 23) 調整了權限授權行為,小明的 App 使
用了列為危險權限的「READ_CONTACTS」。
他的 App compileSdkVersion 為 23,targetSdkVersion 為 21
請問小明的 App 可以不做 runtime permission 的調整在 Android 6.0
的手機上執行嗎?
A: 可以,只要 targetSdkVersion 未升至行為變更的版本,就能繼續向下
相容
背景執行限制
This presentation is provided on a strictly private and confidential basis for information purposes only.
背景執行限制
Android 8.0 為提高電池續航時間,當 App 進入背景且沒有執行中的
Service,系統會解除 App 持有的 wakelocks 並限制其操作。
• 背景服務限制
• 廣播限制
This presentation is provided on a strictly private and confidential basis for information purposes only.
背景服務限制 - 在背景時如何啟動服務? (1/2)
❖ Android 8.0 以前
➢ 可在背景啟動服務,依據需求再提高為前景服務
Context.startService(serviceIntent);
Service.startForeground(notificationId, notification);
This presentation is provided on a strictly private and confidential basis for information purposes only.
❖ Android 8.0 以前
➢ 可在背景啟動服務,依據需求再提高為前景服務
Context.startService(serviceIntent);
Service.startForeground(notificationId, notification);
❖ Android 8.0 以後
➢ 先透過新的 API 啟動前台服務,接著在 5 秒內設為前景服務
Context.startForegroundService()
Service.startForeground(notificationId, notification);
背景服務限制 - 在背景時如何啟動服務? (2/2)
This presentation is provided on a strictly private and confidential basis for information purposes only.
❖ Android 8.0 以前
➢ 可在背景啟動服務,依據需求再提高為前景服務
Context.startService(serviceIntent);
Service.startForeground(notificationId, notification);
❖ Android 8.0 以後
➢ 先透過新的 API 啟動前台服務,接著在 5 秒內設為前景服務
Context.startForegroundService()
Service.startForeground(notificationId, notification);
背景服務限制 - 在背景時如何啟動服務? (2/2)
若未即時設置會被
系統視為 ANR
This presentation is provided on a strictly private and confidential basis for information purposes only.
廣播限制 - 隱式廣播 (Implicit broadcasts) (1/5)
➢ Explicit Intents
○ 有指定明確目標的 Intent,註冊於 AndroidManifest.xml 中仍可正常接收
This presentation is provided on a strictly private and confidential basis for information purposes only.
➢ Explicit Intents
○ 有指定明確目標的 Intent,註冊於 AndroidManifest.xml 中仍可正常接收
➢ Implicit Intents
○ 沒有明確目標的 Intent
註冊在 AndroidManifest.xml 中的 Implicit Intent Receiver 會收不到 Intent
廣播限制 - 隱式廣播 (Implicit broadcasts) (2/5)
This presentation is provided on a strictly private and confidential basis for information purposes only.
● 例外的 Implicit Intent,仍可繼續在 AndroidManifest.xml 中監聽
○ ACTION_LOCKED_BOOT_COMPLETED, ACTION_BOOT_COMPLETED
○ ACTION_USER_INITIALIZE
○ ACTION_LOCALE_CHANGED
○ ACTION_USB_ACCESSORY_ATTACHED, ACTION_USB_ACCESSORY_DETACHED,
ACTION_USB_DEVICE_ATTACHED, ACTION_USB_DEVICE_DETACHED
○ ACTION_CONNECTION_STATE_CHANGED, ACTION_CONNECTION_STATE_CHANGED,
ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECTED
○ ACTION_CARRIER_CONFIG_CHANGED
○ LOGIN_ACCOUNTS_CHANGED_ACTION
○ ACTION_PACKAGE_DATA_CLEARED
○ ACTION_PACKAGE_FULLY_REMOVED
○ ACTION_NEW_OUTGOING_CALL
○ ACTION_DEVICE_OWNER_CHANGED
○ ACTION_EVENT_REMINDER
○ ACTION_MEDIA_MOUNTED, ACTION_MEDIA_CHECKING, ACTION_MEDIA_UNMOUNTED,
ACTION_MEDIA_EJECT, ACTION_MEDIA_UNMOUNTABLE, ACTION_MEDIA_REMOVED,
ACTION_MEDIA_BAD_REMOVAL
○ SMS_RECEIVED_ACTION, WAP_PUSH_RECEIVED_ACTION
廣播限制 - 隱式廣播 (Implicit broadcasts) (3/5)
This presentation is provided on a strictly private and confidential basis for information purposes only.
❖ 未在例外中的隱式廣播該如何監聽?
➢ Runtime 在 Java code 中註冊
廣播限制 - 隱式廣播 (Implicit broadcasts) (4/5)
This presentation is provided on a strictly private and confidential basis for information purposes only.
❖ 未在例外中的隱式廣播該如何監聽?
➢ Runtime 在 Java code 中註冊
➢ 或改用 JobScheduler
廣播限制 - 隱式廣播 (Implicit broadcasts) (5/5)
This presentation is provided on a strictly private and confidential basis for information purposes only.
背景執行限制 - JobIntentService (1/2)
用來執行加入至 JobScheduler 中的 Job 的輔助工具
This presentation is provided on a strictly private and confidential basis for information purposes only.
背景執行限制 - JobIntentService (2/2)
This presentation is provided on a strictly private and confidential basis for information purposes only.
背景執行限制 - JobIntentService (2/2)
Android O 以下被視為普通的 IntentService 使用 startService() 來執行
Notification Channel
Notification Channel (1/4)
一般來說,我們會這樣寫..
Notification Channel (2/4)
但 Constructor 在 API level 26.1.0 被棄用了
Notification Channel (3/4)
需先建立 Notification Channel
Notification Channel (4/4)
需先建立 Notification Channel,再發送通知
Notification Channel (4/4)
需先建立 Notification Channel,再發送通知
指定這則通知使用哪個 Channel
Alert Windows
This presentation is provided on a strictly private and confidential basis for information purposes only.
Alert Windows (1/2)
使用 SYSTEM_ALERT_WINDOW 權限的 App 無法再使用以下類型參數來顯示在其他 App 之上
This presentation is provided on a strictly private and confidential basis for information purposes only.
Alert Windows (2/2)
須改用
另外有一些新的特性
• 浮動視窗始終顯示在狀態欄和輸入法下方
• 系統可移動浮動視窗或調整其大小
• 用戶可透過系統狀態欄關閉浮動視窗
GCM Service
This presentation is provided on a strictly private and confidential basis for information purposes only.
GCM Service (1/3)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent {
act=com.google.android.c2dm.intent.RECEIVE app is in background}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505)
at android.app.ContextImpl.startService(ContextImpl.java:1461)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at
android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99)
at com.google.android.gms.gcm.GcmReceiver.doStartService(GcmReceiver.java:22)
at com.google.android.gms.gcm.GcmReceiver.zzd(GcmReceiver.java:0)
at com.google.android.gms.gcm.GcmReceiver.onReceive(GcmReceiver.java:98)
當 App 未啟動時收到推播..
This presentation is provided on a strictly private and confidential basis for information purposes only.
GCM Service (2/3)
AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdReceiver:
java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.MESSAGING_EVENT
app is in background }
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
升ㄔ
轉移至 FCM (Firebase Cloud Messaging) 後..
This presentation is provided on a strictly private and confidential basis for information purposes only.
GCM Service (3/3)
升ㄔ
關注 Firebase Android SDK 釋出的修正!
● Release notes: https://firebase.google.com/support/release-notes/android
● Reference:
https://stackoverflow.com/questions/46117554/firebasemessagingservice-crashes-on-android-o-d
ue-to-background-execution-limits#comment81612160_46117554
AudioAttributes
This presentation is provided on a strictly private and confidential basis for information purposes only.
AudioAttributes (1/2)
所有音頻相關的 API 都應改用 AudioAttributes 來描述 use case
原來的寫法:
This presentation is provided on a strictly private and confidential basis for information purposes only.
AudioAttributes (2/2)
所有音頻相關的 API 都應改用 AudioAttributes 來描述 use case
新的寫法:
This presentation is provided on a strictly private and confidential basis for information purposes only.
References
● https://developer.android.com/about/versions/oreo/android-8.0-changes.html
● https://developer.android.com/about/versions/oreo/android-8.0-migration.html
● https://developer.android.com/about/versions/oreo/background.html
● https://medium.com/exploring-android/exploring-background-execution-limits-on-android-oreo-ab384762a66c
● https://developers.google.com/cloud-messaging/android/android-migrate-fcm
Q & A
This presentation is provided on a strictly private and confidential basis for information purposes only.
THANK YOU

More Related Content

Similar to Migrating to Android 8.0

Rhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesRhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesKonstantin Rybas
 
Using the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidUsing the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidXavier Hallade
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Embarcadero Technologies
 
[@NaukriEngineering] Introduction to Android O
[@NaukriEngineering] Introduction to Android O[@NaukriEngineering] Introduction to Android O
[@NaukriEngineering] Introduction to Android ONaukri.com
 
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16AppDynamics
 
Google I/O conference: Announcement of Android N release
Google I/O conference: Announcement of Android N releaseGoogle I/O conference: Announcement of Android N release
Google I/O conference: Announcement of Android N releaseiMOBDEV Technologies Pvt. Ltd.
 
Cyanogen Platform SDK
Cyanogen Platform SDKCyanogen Platform SDK
Cyanogen Platform SDKAdnan Begovic
 
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Ryo Jin
 
Deliver your App Anywhere … Publicly or Privately
Deliver your App Anywhere … Publicly or PrivatelyDeliver your App Anywhere … Publicly or Privately
Deliver your App Anywhere … Publicly or PrivatelyDevOps.com
 
VMworld 2013: Android in the enterprise: Understand the challenges and how to...
VMworld 2013: Android in the enterprise: Understand the challenges and how to...VMworld 2013: Android in the enterprise: Understand the challenges and how to...
VMworld 2013: Android in the enterprise: Understand the challenges and how to...VMworld
 
PRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfPRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfAvinashDesireddy
 
Kubernetes Security Workshop
Kubernetes Security WorkshopKubernetes Security Workshop
Kubernetes Security WorkshopMirantis
 
JioStoreSTB-JioAdsIntegration.pdf
JioStoreSTB-JioAdsIntegration.pdfJioStoreSTB-JioAdsIntegration.pdf
JioStoreSTB-JioAdsIntegration.pdfHaritvKrishnagiri
 
Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30Somkiat Khitwongwattana
 
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaDeveloping Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaYahoo Developer Network
 
Security, Automation and the Software Supply Chain
Security, Automation and the Software Supply ChainSecurity, Automation and the Software Supply Chain
Security, Automation and the Software Supply ChainOlyaSurits
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NImam Raza
 

Similar to Migrating to Android 8.0 (20)

Rhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesRhomobile 5.5 Release Notes
Rhomobile 5.5 Release Notes
 
Using the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidUsing the Presentation API and external screens on Android
Using the Presentation API and external screens on Android
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
 
[@NaukriEngineering] Introduction to Android O
[@NaukriEngineering] Introduction to Android O[@NaukriEngineering] Introduction to Android O
[@NaukriEngineering] Introduction to Android O
 
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16
Improved Interaction with Mobile User Interaction: Tips and Tricks - AppSphere16
 
Google I/O conference: Announcement of Android N release
Google I/O conference: Announcement of Android N releaseGoogle I/O conference: Announcement of Android N release
Google I/O conference: Announcement of Android N release
 
Cyanogen Platform SDK
Cyanogen Platform SDKCyanogen Platform SDK
Cyanogen Platform SDK
 
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
 
Deliver your App Anywhere … Publicly or Privately
Deliver your App Anywhere … Publicly or PrivatelyDeliver your App Anywhere … Publicly or Privately
Deliver your App Anywhere … Publicly or Privately
 
Android Presentation By Ashok Kumar Pachauri
Android Presentation By Ashok Kumar PachauriAndroid Presentation By Ashok Kumar Pachauri
Android Presentation By Ashok Kumar Pachauri
 
VMworld 2013: Android in the enterprise: Understand the challenges and how to...
VMworld 2013: Android in the enterprise: Understand the challenges and how to...VMworld 2013: Android in the enterprise: Understand the challenges and how to...
VMworld 2013: Android in the enterprise: Understand the challenges and how to...
 
PRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfPRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdf
 
Kubernetes Security Workshop
Kubernetes Security WorkshopKubernetes Security Workshop
Kubernetes Security Workshop
 
Making Network Security Relevant
Making Network Security RelevantMaking Network Security Relevant
Making Network Security Relevant
 
JioStoreSTB-JioAdsIntegration.pdf
JioStoreSTB-JioAdsIntegration.pdfJioStoreSTB-JioAdsIntegration.pdf
JioStoreSTB-JioAdsIntegration.pdf
 
Android Presentation By Ashok Kumar Pachauri
Android Presentation By Ashok Kumar PachauriAndroid Presentation By Ashok Kumar Pachauri
Android Presentation By Ashok Kumar Pachauri
 
Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30
 
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaDeveloping Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
 
Security, Automation and the Software Supply Chain
Security, Automation and the Software Supply ChainSecurity, Automation and the Software Supply Chain
Security, Automation and the Software Supply Chain
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android N
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Migrating to Android 8.0

  • 1. Migrating to Android 8.0 presented by Daniel Deng 2017/11/30
  • 2. This presentation is provided on a strictly private and confidential basis for information purposes only. Daniel Deng Android Developer FB: Daniel Deng LinkedIn: daniel-deng-97742454
  • 3. This presentation is provided on a strictly private and confidential basis for information purposes only. 今天不會介紹 Android Oreo 的新功能
  • 4. This presentation is provided on a strictly private and confidential basis for information purposes only. 也不會逐一說明所有的 API 變更 詳情請自行參閱 https://developer.android.com/about/versions/oreo/android-8.0-changes.html
  • 5. This presentation is provided on a strictly private and confidential basis for information purposes only. 那今天要介紹什麼 ?
  • 6. This presentation is provided on a strictly private and confidential basis for information purposes only. 我們實際將 targetSdkVersion 升至 Android 8.0 遇到的問題
  • 7. This presentation is provided on a strictly private and confidential basis for information purposes only. Outline • 關於版本 • 背景執行限制 • Notification Channel • Alert Windows • GCM Service • AudioAttributes
  • 8. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (1/5) • minSdkVersion • compileSdkVersion • targetSdkVersion
  • 9. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (2/5) • minSdkVersion • 允許安裝的最低版本要求 • 會相依使用的 Library 中的 minSdkVersion • 參考 Android OS 分佈統計決定 2017/11/9 Android OS 版本占比
  • 10. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (3/5) • compileSdkVersion • 使用哪個 Android SDK 版本編譯 • 編譯後可能會出現錯誤或警告 • 會出現低於此版本的棄用 API 警告 • 至少需和使用的 Support Library 同個版本
  • 11. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (4/5) • targetSdkVersion • 向下兼容至哪個版本 • 會套用該版本的行為變化 • 一定要事先測試
  • 12. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (5/5) Q: Android 6.0 (API Level 23) 調整了權限授權行為,小明的 App 使 用了列為危險權限的「READ_CONTACTS」。 他的 App compileSdkVersion 為 23,targetSdkVersion 為 21 請問小明的 App 可以不做 runtime permission 的調整在 Android 6.0 的手機上執行嗎?
  • 13. This presentation is provided on a strictly private and confidential basis for information purposes only. 關於版本 (5/5) Q: Android 6.0 (API Level 23) 調整了權限授權行為,小明的 App 使 用了列為危險權限的「READ_CONTACTS」。 他的 App compileSdkVersion 為 23,targetSdkVersion 為 21 請問小明的 App 可以不做 runtime permission 的調整在 Android 6.0 的手機上執行嗎? A: 可以,只要 targetSdkVersion 未升至行為變更的版本,就能繼續向下 相容
  • 15. This presentation is provided on a strictly private and confidential basis for information purposes only. 背景執行限制 Android 8.0 為提高電池續航時間,當 App 進入背景且沒有執行中的 Service,系統會解除 App 持有的 wakelocks 並限制其操作。 • 背景服務限制 • 廣播限制
  • 16. This presentation is provided on a strictly private and confidential basis for information purposes only. 背景服務限制 - 在背景時如何啟動服務? (1/2) ❖ Android 8.0 以前 ➢ 可在背景啟動服務,依據需求再提高為前景服務 Context.startService(serviceIntent); Service.startForeground(notificationId, notification);
  • 17. This presentation is provided on a strictly private and confidential basis for information purposes only. ❖ Android 8.0 以前 ➢ 可在背景啟動服務,依據需求再提高為前景服務 Context.startService(serviceIntent); Service.startForeground(notificationId, notification); ❖ Android 8.0 以後 ➢ 先透過新的 API 啟動前台服務,接著在 5 秒內設為前景服務 Context.startForegroundService() Service.startForeground(notificationId, notification); 背景服務限制 - 在背景時如何啟動服務? (2/2)
  • 18. This presentation is provided on a strictly private and confidential basis for information purposes only. ❖ Android 8.0 以前 ➢ 可在背景啟動服務,依據需求再提高為前景服務 Context.startService(serviceIntent); Service.startForeground(notificationId, notification); ❖ Android 8.0 以後 ➢ 先透過新的 API 啟動前台服務,接著在 5 秒內設為前景服務 Context.startForegroundService() Service.startForeground(notificationId, notification); 背景服務限制 - 在背景時如何啟動服務? (2/2) 若未即時設置會被 系統視為 ANR
  • 19. This presentation is provided on a strictly private and confidential basis for information purposes only. 廣播限制 - 隱式廣播 (Implicit broadcasts) (1/5) ➢ Explicit Intents ○ 有指定明確目標的 Intent,註冊於 AndroidManifest.xml 中仍可正常接收
  • 20. This presentation is provided on a strictly private and confidential basis for information purposes only. ➢ Explicit Intents ○ 有指定明確目標的 Intent,註冊於 AndroidManifest.xml 中仍可正常接收 ➢ Implicit Intents ○ 沒有明確目標的 Intent 註冊在 AndroidManifest.xml 中的 Implicit Intent Receiver 會收不到 Intent 廣播限制 - 隱式廣播 (Implicit broadcasts) (2/5)
  • 21. This presentation is provided on a strictly private and confidential basis for information purposes only. ● 例外的 Implicit Intent,仍可繼續在 AndroidManifest.xml 中監聽 ○ ACTION_LOCKED_BOOT_COMPLETED, ACTION_BOOT_COMPLETED ○ ACTION_USER_INITIALIZE ○ ACTION_LOCALE_CHANGED ○ ACTION_USB_ACCESSORY_ATTACHED, ACTION_USB_ACCESSORY_DETACHED, ACTION_USB_DEVICE_ATTACHED, ACTION_USB_DEVICE_DETACHED ○ ACTION_CONNECTION_STATE_CHANGED, ACTION_CONNECTION_STATE_CHANGED, ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECTED ○ ACTION_CARRIER_CONFIG_CHANGED ○ LOGIN_ACCOUNTS_CHANGED_ACTION ○ ACTION_PACKAGE_DATA_CLEARED ○ ACTION_PACKAGE_FULLY_REMOVED ○ ACTION_NEW_OUTGOING_CALL ○ ACTION_DEVICE_OWNER_CHANGED ○ ACTION_EVENT_REMINDER ○ ACTION_MEDIA_MOUNTED, ACTION_MEDIA_CHECKING, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_EJECT, ACTION_MEDIA_UNMOUNTABLE, ACTION_MEDIA_REMOVED, ACTION_MEDIA_BAD_REMOVAL ○ SMS_RECEIVED_ACTION, WAP_PUSH_RECEIVED_ACTION 廣播限制 - 隱式廣播 (Implicit broadcasts) (3/5)
  • 22. This presentation is provided on a strictly private and confidential basis for information purposes only. ❖ 未在例外中的隱式廣播該如何監聽? ➢ Runtime 在 Java code 中註冊 廣播限制 - 隱式廣播 (Implicit broadcasts) (4/5)
  • 23. This presentation is provided on a strictly private and confidential basis for information purposes only. ❖ 未在例外中的隱式廣播該如何監聽? ➢ Runtime 在 Java code 中註冊 ➢ 或改用 JobScheduler 廣播限制 - 隱式廣播 (Implicit broadcasts) (5/5)
  • 24. This presentation is provided on a strictly private and confidential basis for information purposes only. 背景執行限制 - JobIntentService (1/2) 用來執行加入至 JobScheduler 中的 Job 的輔助工具
  • 25. This presentation is provided on a strictly private and confidential basis for information purposes only. 背景執行限制 - JobIntentService (2/2)
  • 26. This presentation is provided on a strictly private and confidential basis for information purposes only. 背景執行限制 - JobIntentService (2/2) Android O 以下被視為普通的 IntentService 使用 startService() 來執行
  • 29. Notification Channel (2/4) 但 Constructor 在 API level 26.1.0 被棄用了
  • 31. Notification Channel (4/4) 需先建立 Notification Channel,再發送通知
  • 32. Notification Channel (4/4) 需先建立 Notification Channel,再發送通知 指定這則通知使用哪個 Channel
  • 34. This presentation is provided on a strictly private and confidential basis for information purposes only. Alert Windows (1/2) 使用 SYSTEM_ALERT_WINDOW 權限的 App 無法再使用以下類型參數來顯示在其他 App 之上
  • 35. This presentation is provided on a strictly private and confidential basis for information purposes only. Alert Windows (2/2) 須改用 另外有一些新的特性 • 浮動視窗始終顯示在狀態欄和輸入法下方 • 系統可移動浮動視窗或調整其大小 • 用戶可透過系統狀態欄關閉浮動視窗
  • 37. This presentation is provided on a strictly private and confidential basis for information purposes only. GCM Service (1/3) Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE app is in background} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505) at android.app.ContextImpl.startService(ContextImpl.java:1461) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99) at com.google.android.gms.gcm.GcmReceiver.doStartService(GcmReceiver.java:22) at com.google.android.gms.gcm.GcmReceiver.zzd(GcmReceiver.java:0) at com.google.android.gms.gcm.GcmReceiver.onReceive(GcmReceiver.java:98) 當 App 未啟動時收到推播..
  • 38. This presentation is provided on a strictly private and confidential basis for information purposes only. GCM Service (2/3) AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.MESSAGING_EVENT app is in background } at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259) at android.app.ActivityThread.-wrap17(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 升ㄔ 轉移至 FCM (Firebase Cloud Messaging) 後..
  • 39. This presentation is provided on a strictly private and confidential basis for information purposes only. GCM Service (3/3) 升ㄔ 關注 Firebase Android SDK 釋出的修正! ● Release notes: https://firebase.google.com/support/release-notes/android ● Reference: https://stackoverflow.com/questions/46117554/firebasemessagingservice-crashes-on-android-o-d ue-to-background-execution-limits#comment81612160_46117554
  • 41. This presentation is provided on a strictly private and confidential basis for information purposes only. AudioAttributes (1/2) 所有音頻相關的 API 都應改用 AudioAttributes 來描述 use case 原來的寫法:
  • 42. This presentation is provided on a strictly private and confidential basis for information purposes only. AudioAttributes (2/2) 所有音頻相關的 API 都應改用 AudioAttributes 來描述 use case 新的寫法:
  • 43. This presentation is provided on a strictly private and confidential basis for information purposes only. References ● https://developer.android.com/about/versions/oreo/android-8.0-changes.html ● https://developer.android.com/about/versions/oreo/android-8.0-migration.html ● https://developer.android.com/about/versions/oreo/background.html ● https://medium.com/exploring-android/exploring-background-execution-limits-on-android-oreo-ab384762a66c ● https://developers.google.com/cloud-messaging/android/android-migrate-fcm
  • 44. Q & A
  • 45. This presentation is provided on a strictly private and confidential basis for information purposes only. THANK YOU