Android 10 privacy changes for accessing device location

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?