Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dfe81d8

Browse files
committedMar 20, 2017
use new permission api in gps example
1 parent 9192716 commit dfe81d8

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed
 

‎location_permissions/gps_example/gps_example.pde

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ PFont androidFont;
3535
boolean hasLocation = false;
3636

3737
void 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

4546
void 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);

4 commit comments

Comments
 (4)

xuv commented on Mar 28, 2017

@xuv

@codeanticode Sorry to bother with this question, but are these changes related to the Version 4.0-beta5 of the Android mode or something else?

codeanticode commented on Mar 29, 2017

@codeanticode
OwnerAuthor

no, the upcoming beta6.

xuv commented on Mar 29, 2017

@xuv

Thx

codeanticode commented on Mar 29, 2017

@codeanticode
OwnerAuthor

More info about the new grant request API is here.

This repository has been archived.