• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android [Java] How to fix broken extension?

P

Pamela Howard

Guest
disclaimer: i'm not sure if this is the correct subforum, feel free to move me

I was using "Device Location" by Rani_sputnik for my Android game. This extension has since been removed and no fix has been released publicly by the developer. As my game relies heavily on this feature, and my knowledge of Java is basically nil, I'm in a bit of a pickle :pickle:

I have uploaded the code in the .java file here for all of you to look through. I'm getting the following Lint errors:

MissingPermission: Missing Permissions
../../src/main/java/com/StudioName/GameName/GMGeolocation.java:24: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
21 // Acquire a reference to the system Location Manager
22 locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
23 // Try and restore the current location from a cached value
24 provideLocation(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));

25 provideLocation(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
26 }});
../../src/main/java/com/StudioName/GameName/GMGeolocation.java:25: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
22 locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
23 // Try and restore the current location from a cached value
24 provideLocation(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
25 provideLocation(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));

26 }});
27 }
../../src/main/java/com/StudioName/GameName/GMGeolocation.java:52: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
49 };
50
51 // Register the listener with the Location Manager to receive location updates
52 locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

53 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
54 watching = true;
../../src/main/java/com/StudioName/GameName/GMGeolocation.java:53: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
50
51 // Register the listener with the Location Manager to receive location updates
52 locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
53 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

54 watching = true;
55 }});
../../src/main/java/com/StudioName/GameName/GMGeolocation.java:65: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
62 Log.i("yoyo","Ending location watch");
63 RunnerActivity.ViewHandler.post( new Runnable() {
64 public void run() {
65 locationManager.removeUpdates(locationListener);

66 watching = false;
67 }});
Note: This issue has an associated quickfix operation in Android Studio/IntelliJ Fix
Priority: 9 / 10
Category: Correctness
Severity: Error
Explanation: Missing Permissions.
This check scans through your code and libraries and looks at the APIs being used, and checks this against the set of permissions required to access those APIs. If the code using those APIs is called at runtime, then the program will crash.

Furthermore, for permissions that are revocable (with targetSdkVersion 23), client code must also be prepared to handle the calls throwing an exception if the user rejects the request for permission at runtime.

More info:

To suppress this error, use the issue id "MissingPermission" as explained in the Suppressing Warnings and Errors section.
 
Top