Created
          November 25, 2013 13:24 
        
      - 
      
- 
        Save donaldhuebner/7641122 to your computer and use it in GitHub Desktop. 
    Verifying Google Play Services
  
        
  
    
      This file contains hidden or 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 AuthActivity extends Activity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.main); | |
| } | |
| } | |
| @Override | |
| protected void onResume() { | |
| super.onResume(); | |
| if (checkPlayServices()) { | |
| // Then we're good to go! | |
| } | |
| } | |
| private boolean checkPlayServices() { | |
| int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); | |
| if (status != ConnectionResult.SUCCESS) { | |
| if (GooglePlayServicesUtil.isUserRecoverableError(status)) { | |
| showErrorDialog(status); | |
| } else { | |
| Toast.makeText(this, "This device is not supported.", | |
| Toast.LENGTH_LONG).show(); | |
| finish(); | |
| } | |
| return false; | |
| } | |
| return true; | |
| } | |
| void showErrorDialog(int code) { | |
| GooglePlayServicesUtil.getErrorDialog(code, this, | |
| REQUEST_CODE_RECOVER_PLAY_SERVICES).show(); | |
| } | |
| static final int REQUEST_CODE_RECOVER_PLAY_SERVICES = 1001; | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| switch (requestCode) { | |
| case REQUEST_CODE_RECOVER_PLAY_SERVICES: | |
| if (resultCode == RESULT_CANCELED) { | |
| Toast.makeText(this, "Google Play Services must be installed.", | |
| Toast.LENGTH_SHORT).show(); | |
| finish(); | |
| } | |
| return; | |
| } | |
| super.onActivityResult(requestCode, resultCode, data); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Very good example. Thank you