6. Setting Up Google Play Services
Module build.gradle
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.google.android.gms:play-services-fitness:7.3.0'
compile 'com.google.android.gms:play-services-wearable:7.3.0'
}
7. Setting Up Google Play Services
Google+ com.google.android.gms:play-services-plus:7.3.0
Google Account Login com.google.android.gms:play-services-identity:7.3.0
Google Actions, Base Client Library com.google.android.gms:play-services-base:7.3.0
Google App Indexing com.google.android.gms:play-services-appindexing:7.3.0
Google Analytics com.google.android.gms:play-services-analytics:7.3.0
Google Cloud Messaging com.google.android.gms:play-services-gcm:7.3.0
Google Drive com.google.android.gms:play-services-drive:7.3.0
Google Fit com.google.android.gms:play-services-fitness:7.3.0
Google Location, Activity Recognition, and Places com.google.android.gms:play-services-location:7.3.0
Google Maps com.google.android.gms:play-services-maps:7.3.0
Google Mobile Ads com.google.android.gms:play-services-ads:7.3.0
...
8. Setting Up Google Play Services
In Activity... implements ConnectionCallbacks, OnConnectionFailedListener
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
9. Setting Up Google Play Services
In Activity...
@Override
protected void onStart() {
super.onStart();
if (!mResolvingError) { // more about this later
mGoogleApiClient.connect();
}
}
@Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
10. Handle connection failures
In Activity...
@Override
public void onConnected(Bundle connectionHint) { }
@Override
public void onConnectionSuspended(int cause) { }
@Override
public void onConnectionFailed(ConnectionResult result) { }
12. Handle Connection Failures
In Activity...
private void showErrorDialog(int errorCode) {
ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
Bundle args = new Bundle();
args.putInt(DIALOG_ERROR, errorCode);
dialogFragment.setArguments(args);
dialogFragment.show(getSupportFragmentManager(), DIALOG_ERROR);
}
public void onDialogDismissed() { mResolvingError = false; }
13. Handle Connection Failures
In Activity...
public static class ErrorDialogFragment extends DialogFragment {
public ErrorDialogFragment() { }
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int errorCode = this.getArguments().getInt(DIALOG_ERROR);
return GooglePlayServicesUtil.getErrorDialog(errorCode,
this.getActivity(), REQUEST_RESOLVE_ERROR);
}
@Override
public void onDismiss(DialogInterface dialog) {
((MainActivity)getActivity()).onDialogDismissed();
}
}
14. Handle Connection Failures
In Activity...
public static class ErrorDialogFragment extends DialogFragment {
public ErrorDialogFragment() { }
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int errorCode = this.getArguments().getInt(DIALOG_ERROR);
return GooglePlayServicesUtil.getErrorDialog(errorCode,
this.getActivity(), REQUEST_RESOLVE_ERROR);
}
@Override
public void onDismiss(DialogInterface dialog) {
((MainActivity)getActivity()).onDialogDismissed();
}
}
15. Handle Connection Failures
In Activity...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
16. Handle Connection Failures
In Activity...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
17. Google Maps Android API v2
Features
3D maps; Indoor, satellite, terrain, and hybrid maps; Vector-based
tiles for efficient caching and drawing; Animated transitions
Customize the map; Control the user's view; Street View
19. Android Certificate and API Key
Create Project On: https://console.developers.google.com/project
Activate Google Maps Android API
Create a New Key for Android: [SHAI Key];[Prject Path]
Get the Google Maps API key Generated: AIz … VgHcNL7Sg
22. Map Type
GoogleMap map; map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
MAP_TYPE_HYBRID - Satellite maps with a transparent layer of major streets.
MAP_TYPE_NONE - No base map tiles.
MAP_TYPE_NORMAL - Basic maps.
MAP_TYPE_SATELLITE - Satellite maps with no labels.
MAP_TYPE_TERRAIN - Terrain maps.