Android 10 privacy changes for accessing device location
文章推薦指數: 80 %
Android 10 introduces new location permission, ACCESS_BACKGROUND_LOCATION when you target Android 10. If your app targets Android 9 (API level 28) or lower, ... OpeninappHomeNotificationsListsStoriesWritePublishedinProAndroidDevAndroid10privacychangesforaccessingdevicelocationAndroid10givesusersmorecontroloverwhenappscangetaccesstodevicelocation.WhenanapprunningonAndroid10requestslocationaccess,usersseethedialogshowninFigure.Thisdialogallowsuserstograntlocationaccesstotwodifferentextents:whileusingtheapp(foregroundonly)orallthetime(foregroundandbackground).“Allthetime”—thismeansanappcanaccesslocationatanytime“Whileinuse”—thismeansanappcanaccesslocationonlywhiletheappisbeingused“Deny”—thismeansanappcannotaccessthelocationNewpermissionadded:Android10introducesnewlocationpermission,ACCESS_BACKGROUND_LOCATIONwhenyoutargetAndroid10.IfyourapptargetsAndroid9(APIlevel28)orlower,theACCESS_BACKGROUND_LOCATIONpermissionwillbeautomaticallyaddedforyoubythesystemifyourequesteitherACCESS_FINE_LOCATIONorACCESS_COARSE_LOCATION.AlthoughyourappcanrequestandreceivetheACCESS_BACKGROUND_LOCATIONpermission,theusercanrevokethispermissionbychoosingthatyourappshouldaccesslocationinformationonlyintheforeground.YoucanalsocheckiftheappallowsthelocationtofetchintheforegroundorbackgroundusingthecheckSelfPermissionmethod.Iftheuserhasgivenyourappforeground-onlyaccesstolocation,theusermightstilllaunchaworkflowthatrequiresyourapptoaccesstheirlocation,evenaftertheuserpressestheHomebuttonontheirdeviceorturnstheirdevice’sdisplayoff.Toretainaccesstothedevice’slocationinthisspecificusecase,startaforegroundservicewithforegroundServiceType=”location”Beforestartingtheforegroundservice,makesurethatyourappstillhasaccesstothedevice’slocation:Ifyoudonotdeclareforegroundservicetypelocationandiftheuserhasprovidedonlywhile-in-usepermissionyourappcannotgetthelocationwhilerunningtheforegroundservice.Iftheapphasall-in-timepermissionyourappwillgetthelocationwhilerunningtheforegroundservicewithoutthisdeclarationinthemanifest.ThischangeisforalltheappsirrespectiveofthetargetSDKversion.ChangesinlocationpermissionafterdeviceupgradetoAndroidQAskforpermissionsonlywhenneeded:Don’trequestlocationpermissionatappstartupunlessabsolutelynecessary.IfyourapptargetsAndroid10andneedsaccesstolocationinformationonlywhenrunningintheforeground,don’trequestACCESS_BACKGROUND_LOCATION.LocationReminderNotifications:Locationinformationissensitiveanduserssharesensitivedatalikelocationwhenitmakessensebuttheusercanforgetthelevelofpermissiongiventotheappssothisfeaturewillsendanotificationtotheusersiftheappaccessthedevicelocationwhentheuserisnotactivelyusingtheapp.Whendoestheusergetthisnotification?Userswillgetonetimeperappnotificationwhentheuserprovidesall-the-timelocationpermissiontotheapp,andtheappreceivedafinelocationupdateinthebackground.WI-FIAPIsandlocationpermission:Androidit'spossibletogetindirectlocationaccessfromconnectivityAPIsspeciallyWi-FiAPIs.ApplicationssometimeswanttohaveuserstoconnecttoWi-Fidevices.BeforeQAndroidprovidesAPIsforWi-FIconnectivity,ApplicationstypicallydoWi-FIscansfirsttogetalistofnearbywi-fidevicestochoosewhichdevicetoconnectto.KnowingthenearbyWi-Fidevicesmakesitpossibletoderivedevicelocation.SotheseAPIsareprotectedbylocationpermission.Sothismakesusersconfusebecausetheywanttojustconnecttowi-fidevicesbutwhydoestheapprequestlocationpermission?TosolvethisproblemAndroid10introducestwonewAPIsWi-FiNetworkSuggestionandWi-FiNetworkSpecifierUsingtheseAPIsapplicationscantelltheWi-FisystemwhatWi-FidevicestheywanttoconnectandWi-Fisystemwilldothescananddecidewhethertoconnecttothosedevicesornot.ApplicationwillnotgettheinformationofnearbyWi-Fidevicessodoesnotrequirelocationpermission.Wi-FiNetworkSuggestion:Someapplicationsmayknowthecertainnetworksuserscanconnecttowhentheygototheairportorcoffeeshopsorsomeotherplace.OnQsuchanappcanuseWi-FiNetworkSuggestionApitorecommendthosenetworkstotheWi-Fisystems.Wi-FiNetworkSpecifier:UsecaseforthisAPIisausercantakeaphotofromthecameraandwanttotransferphotoslatertothephone.Forimplementationdetailscheckthislink.That’sallfornow!MorefromProAndroidDevFollowThelatestpostsfromAndroidProfessionalsandGoogleDeveloperExperts.ReadmorefromProAndroidDevRecommendedfromMediumDeltaHubCapitalinDeltaHubCapitalLaunchingDHCLiquidityMiningProgramFaunaIncinFaunaBuildinganAuthenticationSaaSwithFaunaDBSiraLam7TipsofAndroidDevelopmentthatbeginnersmaynotknowIdanFriedmanUsingHashicorpPackerforcreatingmachineimagesasapartofautomatedCI/CDpipelinesMalcolmHysonScalablePlatformPerformanceTestingwithAzure — Part3OttoPI’mswitchingtoFedoraSilverblue(fornow)AtulVermaUDF(userdefinefunction)insparkEhmSohninGluonReactorGluonReactor:thedawnofaneweraincross-domaininteroperabilityAboutHelpTermsPrivacyGettheMediumappGetstartedSuchiBansal107FollowersSoftwareEngineer(Android)|Foreverfallingforwaterfallsandwanderlust.”Reachmeat:[email protected]|www.linkedin.com/in/suchi-bansalFollowHelpStatusWritersBlogCareersPrivacyTermsAboutKnowable
延伸文章資訊
- 1Manifest.permission - Android Developers
- 2Exploring Android Q: Location Permissions | by Joe Birch
To support backward compatibility, if your application doesn't target Q then the ACCESS_BACKGROUN...
- 3Despite no ACCESS_BACKGROUND_LOCATION permission ...
java - Android 10 (Q) ACCESS_BACKGROUND_LOCATION ...
- 4请求位置权限| Android 开发者
在Android 10(API 级别29)及更高版本中,您必须在应用的清单中声明 ACCESS_BACKGROUND_LOCATION 权限,以便请求在运行时于后台访问位置信息。
- 5Android 10 privacy changes for accessing device location
Android 10 introduces new location permission, ACCESS_BACKGROUND_LOCATION when you target Android...