質問: locationmanager.getlastknownlocation(locationmanager.gps_provider); if (mylocation != null) { log.d("tag", "not null"); } else { log.d("tag", "null"); locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, this); } } catch (securityexception se) { log.d("tag", "se caught"); se.printstacktrace(); } } @override public void onlocationchanged(location location) { log.d("changed", "location updated"); } @override public void onstatuschanged(string provider, int status, bundle extras) { } @override public void onproviderenabled(string provider) { } @override public void onproviderdisabled(string provider) { } }
回答: 私の簡単な解決策はこれですif (contextcompat.checkselfpermission(this, android.manifest.permission.access_fine_location) == packagemanager.permission_granted && contextcompat.checkselfpermission(this, android.manifest.permission.access_coarse_location) == packagemanager.permission_granted) { googlemap.setmylocationenabled(true); googlemap.getuisettings().setmylocationbuttonenabled(true); } else { toast.maketext(this, r.string.error_permission_map, toast.length_long).show(); } またはあなたはこのように他の人に許可ダイアログを開くことができます} else { activitycompat.requestpermissions(this, new string[] { manifest.permission.access_fine_location, manifest.permission.access_coarse_location }, tag_code_permission_location); }