File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed
location_permissions/gps_example Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -35,16 +35,17 @@ PFont androidFont;
3535boolean hasLocation = false ;
3636
3737void setup () {
38- size ( 480 , 640 , P2D );
39- orientation(PORTRAIT );
38+ fullScreen( );
39+ orientation(PORTRAIT );
4040 fontList = PFont . list();
4141 androidFont = createFont (fontList[0 ], 26 , true );
4242 textFont (androidFont);
43+ requestPermission(" android.permission.ACCESS_FINE_LOCATION" , " initLocation" );
4344}
4445
4546void draw () {
4647 background (0 );
47- if (hasLocation ) {
48+ if (hasPermission( " android.permission.ACCESS_FINE_LOCATION " ) ) {
4849 // Display current GPS data
4950 text (" Latitude: " + currentLatitude, 20 , 40 );
5051 text (" Longitude: " + currentLongitude, 20 , 75 );
@@ -55,19 +56,9 @@ void draw() {
5556 }
5657}
5758
58- void onPermissionsGranted () {
59- initLocation();
60- }
61-
62- void initLocation () {
63- if (checkPermission(Manifest . permission. ACCESS_FINE_LOCATION ) ||
64- checkPermission(Manifest . permission. ACCESS_COARSE_LOCATION )) {
65-
66- // For 3.x versions of the mode
67- // context = getActivity();
68-
69- // For 4.0+ versions of the mode
70- Context context = surface. getContext();
59+ void initLocation (boolean granted ) {
60+ if (granted) {
61+ Context context = getContext();
7162
7263 locationListener = new MyLocationListener ();
7364 locationManager = (LocationManager ) context. getSystemService(Context . LOCATION_SERVICE );
You can’t perform that action at this time.
0 commit comments