Created
March 6, 2017 13:38
-
-
Save piyushgupta27/9ac95da91242e73073120e18a58bc2fc to your computer and use it in GitHub Desktop.
Implementation for requesting Location Permissions and Location Services using HyperTrack APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
... | |
// Check if location settings have been enabled by the user | |
checkForLocationSettings(); | |
} | |
private void checkForLocationSettings() { | |
// Check for Location permission | |
if (!HyperTrack.checkLocationPermission(this)) { | |
HyperTrack.requestPermissions(this); | |
return; | |
} | |
// Check for Location settings | |
if (!HyperTrack.checkLocationServices(this)) { | |
HyperTrack.requestLocationServices(this, null); | |
} | |
// Location Permissions and Settings have been enabled | |
// Proceed with your app logic here | |
} | |
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
if (requestCode == HyperTrack.REQUEST_CODE_LOCATION_PERMISSION) { | |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
checkForLocationSettings(); | |
} else { | |
// Handle Location Permission denied error | |
Toast.makeText(this, "Location Permission denied.", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == HyperTrack.REQUEST_CODE_LOCATION_SERVICES) { | |
if (resultCode == Activity.RESULT_OK) { | |
checkForLocationSettings(); | |
} else { | |
// Handle Enable Location Services request denied error | |
Toast.makeText(this, "Enable Location Services request denied.", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment