- 浏览: 2543106 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Android UI(8)Building Apps with User Info&Location
1. Accessing Contacts Data
…snip…
2. Remembering Users
…snip...
3. Making Your App Location Aware
Download the sample code LocationAware.zip.
3.1 Using the Location Manager
Declare Proper Permissions in Android Manifest
<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Get a Reference to LocationManager
// Get a reference to the LocationManager object.
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Pick a Location Provider
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);finalboolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
3.2 Obtaining the Current Location
Set Up the Location Listener
private final LocationListener listener = new LocationListener() {
public void onLocationChanged(Location location) { updateUILocation(location);}public void onProviderDisabled(String provider) {}public void onProviderEnabled(String provider) {}public void onStatusChanged(String provider, int status, Bundle extras) {}
};
private Location requestUpdatesFromProvider(final String provider,final String errorResId) {
Location location = null;if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, TEN_SECONDS,TEN_METERS, listener); location = locationManager.getLastKnownLocation(provider);} else { Toast.makeText(this, errorResId, Toast.LENGTH_LONG).show();}return location;
}
gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER,"GPS provider is not supported.");networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER,"Network provider is not supported.");
Handle Multiple Sources of Location Updates
…snip...
Terminate Location Updates
locationManager.removeUpdates(listener);
3.3 Displaying the Location Address
It is not working on my device. I do not know if it is working on other device.
geocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();
private class ReverseGeocodingTask extends AsyncTask<Location, Void, Void> {
Context context;public ReverseGeocodingTask(Context context) { super(); this.context = context;}protected Void doInBackground(Location... params) {Geocoder geocoder = new Geocoder(context, Locale.getDefault());Location loc = params[0];List<Address> addresses = null;try { addresses = geocoder.getFromLocation(loc.getLatitude(),loc.getLongitude(), 1);} catch (IOException e) { e.printStackTrace(); // Update address field with the exception. Message.obtain(handler, UPDATE_ADDRESS, e.toString()).sendToTarget();}if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String addressText = String.format( "%s, %s, %s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", address.getLocality(), address.getCountryName());// Update address field on UI. Message.obtain(handler, UPDATE_ADDRESS, addressText).sendToTarget();}return null;}
}
Tips:
1. LocationManager addProximityAlert
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent("com.sillycat.easyrestclientandroid");
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, -1, intent,0);
locationManager.addProximityAlert(lat,lng,radius,expiration,proximityIntent);
public class ProximityIntentReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent){
String key = LocationManager.KEY_PROXIMITY_ENTERING;
boolean entering = intent.getBooleanExtra(key,false);
…snip...
}
}
IntentFilter filter = new IntentFilter("com.sillycat.easyrestclientandroid");
registerReceiver(new ProximityIntentReceiver(),fitler);
2. Android android.app.Service
http://developer.android.com/reference/android/app/Service.html
The lifecycle of Service will be onCreate(), onStart(), onDestroy()
During start ----- onCreate(), onStart(), if the second time to start this service, it will only call onStart()
During stop ----- onDestroy()
There is no UI for service, but it should be always running background.
There are 2 ways to start the Service, Context.startService(), Context.bindService().
Context.startService()
startService ---- onCreate() -----> onStart() Second Time, only onStart()
stopService ---- onDestroy()
If the system did not destroy the service and quit the application, the service will be running on the backend. After we start the service we can check how many services we have in the [Setting] --> [Applications] --> Running Services
Context.bindService()
bindService ---> onCreate() ---> onBind() Second Time, nothing
unbindService ----> onUnbind() ---> onDestory()
onStartCommand
this onStartCommand() will be called after we invoke startService(Intent)
References:
http://developer.android.com/training/building-userinfo.html
http://developer.android.com/training/id-auth/index.html
http://developer.android.com/training/basics/location/index.html
Google Sample
https://code.google.com/p/google-api-java-client/wiki/APIs
https://code.google.com/p/google-api-java-client/source/browse/tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android/TasksSample.java?repo=samples
https://developers.google.com/google-apps/tasks/oauth-and-tasks-on-android
Android Service
http://blog.sina.com.cn/s/blog_3fe961ae0100xhsl.html
http://blog.csdn.net/nkmnkm/article/details/7331297
1. Accessing Contacts Data
…snip…
2. Remembering Users
…snip...
3. Making Your App Location Aware
Download the sample code LocationAware.zip.
3.1 Using the Location Manager
Declare Proper Permissions in Android Manifest
<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Get a Reference to LocationManager
// Get a reference to the LocationManager object.
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Pick a Location Provider
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);finalboolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
3.2 Obtaining the Current Location
Set Up the Location Listener
private final LocationListener listener = new LocationListener() {
public void onLocationChanged(Location location) { updateUILocation(location);}public void onProviderDisabled(String provider) {}public void onProviderEnabled(String provider) {}public void onStatusChanged(String provider, int status, Bundle extras) {}
};
private Location requestUpdatesFromProvider(final String provider,final String errorResId) {
Location location = null;if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, TEN_SECONDS,TEN_METERS, listener); location = locationManager.getLastKnownLocation(provider);} else { Toast.makeText(this, errorResId, Toast.LENGTH_LONG).show();}return location;
}
gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER,"GPS provider is not supported.");networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER,"Network provider is not supported.");
Handle Multiple Sources of Location Updates
…snip...
Terminate Location Updates
locationManager.removeUpdates(listener);
3.3 Displaying the Location Address
It is not working on my device. I do not know if it is working on other device.
geocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();
private class ReverseGeocodingTask extends AsyncTask<Location, Void, Void> {
Context context;public ReverseGeocodingTask(Context context) { super(); this.context = context;}protected Void doInBackground(Location... params) {Geocoder geocoder = new Geocoder(context, Locale.getDefault());Location loc = params[0];List<Address> addresses = null;try { addresses = geocoder.getFromLocation(loc.getLatitude(),loc.getLongitude(), 1);} catch (IOException e) { e.printStackTrace(); // Update address field with the exception. Message.obtain(handler, UPDATE_ADDRESS, e.toString()).sendToTarget();}if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String addressText = String.format( "%s, %s, %s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", address.getLocality(), address.getCountryName());// Update address field on UI. Message.obtain(handler, UPDATE_ADDRESS, addressText).sendToTarget();}return null;}
}
Tips:
1. LocationManager addProximityAlert
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent("com.sillycat.easyrestclientandroid");
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, -1, intent,0);
locationManager.addProximityAlert(lat,lng,radius,expiration,proximityIntent);
public class ProximityIntentReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent){
String key = LocationManager.KEY_PROXIMITY_ENTERING;
boolean entering = intent.getBooleanExtra(key,false);
…snip...
}
}
IntentFilter filter = new IntentFilter("com.sillycat.easyrestclientandroid");
registerReceiver(new ProximityIntentReceiver(),fitler);
2. Android android.app.Service
http://developer.android.com/reference/android/app/Service.html
The lifecycle of Service will be onCreate(), onStart(), onDestroy()
During start ----- onCreate(), onStart(), if the second time to start this service, it will only call onStart()
During stop ----- onDestroy()
There is no UI for service, but it should be always running background.
There are 2 ways to start the Service, Context.startService(), Context.bindService().
Context.startService()
startService ---- onCreate() -----> onStart() Second Time, only onStart()
stopService ---- onDestroy()
If the system did not destroy the service and quit the application, the service will be running on the backend. After we start the service we can check how many services we have in the [Setting] --> [Applications] --> Running Services
Context.bindService()
bindService ---> onCreate() ---> onBind() Second Time, nothing
unbindService ----> onUnbind() ---> onDestory()
onStartCommand
this onStartCommand() will be called after we invoke startService(Intent)
References:
http://developer.android.com/training/building-userinfo.html
http://developer.android.com/training/id-auth/index.html
http://developer.android.com/training/basics/location/index.html
Google Sample
https://code.google.com/p/google-api-java-client/wiki/APIs
https://code.google.com/p/google-api-java-client/source/browse/tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android/TasksSample.java?repo=samples
https://developers.google.com/google-apps/tasks/oauth-and-tasks-on-android
Android Service
http://blog.sina.com.cn/s/blog_3fe961ae0100xhsl.html
http://blog.csdn.net/nkmnkm/article/details/7331297
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1256ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 630ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1649ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 961Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 575Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 715ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 816Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 908Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1333Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 750Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1043Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1096Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 757Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 719Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 462Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 678Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1072Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 2022Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 885IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1318IOS7 App Development Essentials ...
相关推荐
on guide shows you how to build applications that target iOS, Android, and other mobile platforms instead of browsers—apps that can access platform features such as the camera, user location, and ...
on guide shows you how to build applications that target iOS, Android, and other mobile platforms instead of browsers—apps that can access platform features such as the camera, user location, and ...
The Busy Coder’s Guide to Android Development covers a wide range of Android capabilities and APIs, from creating simple user interfaces, to supporting long-running background processes, through the ...
The Android User Interface Basic Widgets Debugging Your App The Classic Container Classes Other Common Widgets and Containers Tutorial #5 - Creating a Layout GUI Building, Continued AdapterViews and ...
This book is a practical guide to solving the everyday problems encountered when building apps for Windows 10 devices, including desktops, laptops, tablets, and phones, using HTML5, CSS3 and ...
Get to grips with Swift 3 and Xcode, the building blocks of Apple development Get to know the fundamentals of Swift, including variables, constants, and control flow Discover the distinctive design ...
- Developing simple apps that showcase basic UI elements and functionalities. - Learning how to handle user input and display information. 3. **Integrating Native Features** - Using JavaScript to ...
Building location-aware iOS applications utilizing Core Location and MapKit Localizing applications for international use Creating applications that capture audio and play media Storing data in files ...
This direct compilation eliminates the need for JavaScript bridges, resulting in apps that perform as well as those built with native technologies. Flutter's high performance is crucial for ...
构建用户界面 (Chapter 7: Building the User Interface) - **布局设计**:讲解如何使用XAML构建灵活且响应式的用户界面布局。 - **样式与模板**:介绍如何定义和应用样式及模板来统一界面外观。 - **动画效果**:...