Google Map and "realtime" data - Tuong-Nguyen/Android GitHub Wiki
References:
- https://developers.google.com/maps/documentation/android-api/start
- https://developers.google.com/maps/documentation/android-api/config
- Code demo
- Install Android SDK
- Add Google Play services package to project https://developers.google.com/android/guides/setup
- Get a Google Maps API key https://developers.google.com/maps/documentation/android-api/signup#use-key
- Add settings to app's manifest
- Specify API key
- Add Android permissions
- Location permission
android.permission.ACCESS_COARSE_LOCATIONorandroid.permission.ACCESS_FINE_LOCATION - External storage permission
android.permission.WRITE_EXTERNAL_STORAGE - Internet access
android.permission.INTERNETandandroid.permission.ACCESS_NETWORK_STATE(will be merged automatically because we used Google Play services)
- Location permission
- Use Android Studio wizard
- https://developers.google.com/maps/documentation/android-api/map
- Plugs Android accounts and authentication framework for handling user credentials (ex: login)
- If don't use user account or login, we still need provide an authenticator component but it's stub
- Bound with a
Servicethat allows the framework call and pass data.
- Create stub
Authenticator - Bind to framework by using Service
- Add metadata file for
Authenticator - Declare
AuthenticatorandAuthenticatorServicein manifest
https://developer.android.com/training/sync-adapters/creating-authenticator.html
- Use to store the local data.
- If run
SyncAdapterwithoutContentProvider, the sync adapter crashes
https://developer.android.com/guide/topics/providers/content-provider-creating.html
- Encapsulates the code of tasks that transfer data between the device and server
- Create a sync adapter by extends
AbsrtactThreadedSyncAdapter- Override
onPerformSync- Connect to server
- Download and upload data
- Handling data conflict
- Clean up
- Override
- Bind
SyncAdapterto framework with aService - Add metadata file
- Declare
SyncAdapterandSyncServicein manifest - Add permissions:
android.permission.INTERNET,android.permission.READ_SYNC_SETTINGS,android.permission.WRITE_SYNC_SETTINGS,android.permission.AUTHENTICATE_ACCOUNTS
https://developer.android.com/training/sync-adapters/creating-sync-adapter.html
- Activity implements
LoaderManager.LoaderCallbacks<Cursor> - Loaders do queries in a background thread
- Can use
ContentObserverthat is triggered when data in the content provider changes. When the sync adapter updates the content provider, the ContentObserver responds by resetting the loader and then reloading it.
