Location sharing and automatic message sender Android Application


Published on

This is the project report of Android Application(Location sharing and Automatic message sender). This report will help users who wants to develop any location based android application.

Published in: Technology, Education
  • can u please mail me the source code........madishettyvicky24@gmail.com
    Are you sure you want to  Yes  No
    Your message goes here
  • kavitaaaaaaa help me please :(
    Are you sure you want to  Yes  No
    Your message goes here
  • I will do a android locator project for my university lesson but ı have got many error .Can you send source code ? I need help , please help me andro.yirmibir@gmail.com
    Are you sure you want to  Yes  No
    Your message goes here
  • can you solve my problem i want to display all the details of hospitals and police stations i am using google places api can you help me to solve out this issue . saurya6890@gmail.com my email id kindly help me
    Are you sure you want to  Yes  No
    Your message goes here
  • i need source code of this project
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Location sharing and automatic message sender Android Application

  2. 2. PLACE-122001 Acknowledgement A research work owes its success from commencement to completion, to the people in love with researchers at various stages. Let me in this page express my gratitude to all those who helped us in various stage of this study. First, I would like to express my sincere gratitude indebtedness to Mr. Alok Kushwaha (HOD, Department of Computer Science & Engineering, Ansal Institute of Technology, Gurgaon) for allowing me to undergo the summer training at Xpert InfoTech in Android Application Development I am grateful to our guide Mr. Narayanan Chandra for the help provided in completion of the project, which was assigned to me. Without his friendly help and guidance it was difficult to develop this project. I am also thankful to Mrs. Anju Bala, Assistant Professor CSE, for her true help, inspiration and for helping me to preparation of the final report and presentation. Last but not least, I pay my sincere thanks and gratitude to all the Staff Members of for their support and for making our training valuable and fruitful. Submitted to: Mrs. Anju Bala Incharge Summer Training IT-2013
  3. 3. Certificate This is to certify that Kavita Sharma of Bachelor of Information Technology ( B.Tech IT) ,has completed Summer Training on the topic Android application Development from Xpert InfoTech , Nirman Vihar , Delhi organization as partial fulfillment of Bachelor of Engineering IT. The summer Training report and presentation by her is genuine work done by her and the same is being submitted for evaluation. Signature Mrs. Anju Bala In charge Summer Training Department of CSE Engineering College Bikaner
  4. 4. Preface Location Tracer and automatic message sender is the android application helps android users to get distance and time to reach a particular destination, when user reached the destination, automatic message will send to the person ,whom user wants to inform that he has reached his destination. This application targeted all android devices tablet, cell phones etc. This Application trace users current location and compare it with the destination location which is set by the user at every one sec, if distance between both locations is less than hundred meter then message will send to a person whose number is set by the user. This application also helps users to get the minimum time required to reach the destination. Users can check distance and time at any time. It also displays route from his location to destination in Google Map with Red marker line. Organization Introduction
  5. 5. XPERT INFOTECH is the largest privately held provider of IT training, enterprise learning services, software and Web Development solutions for information technology (IT) and management professionals. XPERT INFOTECH provides end-to-end learning services and solutions that create a quantifiable path to improved performance and increased knowledge for enterprise customers around India. XPERT INFOTECH the leading learning solutions and professional services provider in India. It focused on meeting the growing need for Information and Communication Technology (ICT) expertise in both global and local markets. Providing its clients with IT Training, Corporate Training, Software development, Web Development and Consultancy Services. XPERT INFOTECH enables its clients to accelerate their business growth through more effective use of ICT in their respective industry. XPERT INFOTECH Training Division is a professional training Company offering IT enabled services & industrial trainings for B.E., B-Tech, MCA, BCA, MSc and MBA fresher’s and experienced Developers/programmers in various platforms. Summer Training /industrial training will be provided for the students of BCA, B-TECH, M.TECH, MBA and MCA only. Deserving candidates may be awarded stipends, scholarships and other benefits, depending on their performance and recommendations of the mentors. 1. Introduction to Android Application Development
  6. 6. World is contracting with the growth of mobile phone technology. As the number of users is increasing day by day, facilities are also increasing. Starting with simple regular handsets which were used just for making phone calls, mobiles have changed our lives and have become part of it. Now they are not used just for making calls but they have innumerable uses and can be used as a Camera , Music player, Tablet PC, T.V. , Web browser etc . And with the new technologies, new software and operating systems are required. Introduction to android: Android is a software bunch comprise not only operating system but also middleware and key applications. Android Inc was founded in Palo Alto of California, U.S. by Andy Rubin, Rich miner, Nick sears and Chris White in 2003. Later Android Inc. was acquired by Google in 2005. After original release there have been number of updates in the original version of Android. Features and Specification Android is a powerful Operating System supporting a large number of applications in Smart Phones. These applications make life more comfortable and advanced for the users. Hardwares that support Android are mainly based on ARM architecture platform. Some of the current features and specifications of android are:
  7. 7. Android comes with an Android market which is an online software store. It was developed by Google. It allows Android users to select, and download applications developed by third party developers and use them. There are around 2.0 lack+ games, application and widgets available on the market for users. Applications These are the basics of Android applications: • Android applications are composed of one or more application components (activities, services, content providers, and broadcast receivers) • Each component performs a different role in the overall application behavior, and each one can be activated individually (even by other applications) • The manifest file must declare all components in the application and should also declare all application requirements, such as the minimum version of Android required and any hardware configurations required • Non-code application resources (images, strings, layout files, etc.) should include alternatives for different device configurations (such as different strings for different languages)
  8. 8. Building blocks to an Android application There are four building blocks to an Android application: Activity Broadcast Intent Receiver Service Content Provider Activity Activities are the most common of the four Android building blocks. An activity is usually a single screen in your application. Each activity is implemented as a single class that extends the Activity base class. Your class will display a user interface composed of Views and respond to events. Most applications consist of multiple screens. For example, a text messaging application might have one screen that shows a list of contacts to send messages to, a second screen to write the message to the chosen contact, and other screens to review old messages or change settings. Each of these screens would be implemented as an activity. Moving to another screen is accomplished by a starting a new activity. In some cases and activity may return a value to the previous activity -- for example an activity that lets the user pick a photo would return the chosen photo to the caller. Intent and Intent Filters Android uses a special class called Intent to move from screen to screen. Intent describes what an application wants done. The two most important parts of the intent data structure are the action and the data to act upon. Typical values for action are MAIN (the front door of the application), VIEW, PICK, EDIT, etc. The data is expressed as a URI. For example, to view contact information for a person, you would create intent with the VIEW action and the data set to a URI representing that person.
  9. 9. There is a related class called an Intent Filter. While an intent is effectively a request to do something, an intent filter is a description of what intents an activity (or Broadcast Receiver, see below) is capable of handling. An activity that is able to display contact information for a person would publish an Intent Filter that said that it knows how to handle the action VIEW when applied to data representing a person. Activities publish their Intent Filters in the AndroidManifest.xml file. . The new activity is informed of the intent, which causes it to be launched. The process of resolving intents happens at run time when start Activity is called, which offers two key benefits: Activities can reuse functionality from other components simply by making a request in the form of an Intent Activities can be replaced at any time by a new Activity with an equivalent Intent Filter BROADCAST INTENT RECEIVER You can use a Broadcast Receiver when you want code in your application to execute in reaction to an external event, for example, when the phone rings, or when the data network is available, or when it's midnight. Broadcast Receivers do not display a UI, although they may use the Notification Manager to alert the user if something interesting has happened. Broadcast Receivers are registered in AndroidManifest.xml, but you can also register them from code using Context.registerReceiver (). Your application does not have to be running for its BroadcastReceivers to be called; the system will start your application, if necessary, when a BroadcastReceiver is triggered. Applications can also send their own intent broadcasts to others with Context.sendBroadcast (). SERVICE A Service is code that is long-lived and runs without a UI. A good example of this is a media player playing songs from a play list. In a media player application, there would probably be one or more activities that allow the user to choose songs and start playing them. However, the music playback itself should not be handled by an activity because the user will expect the music to keep playing even after navigating to a new screen. In this case, the media player activity could start a service using Context.startService () to run in the background to keep the music going. The system will then keep the music playback service running until it has finished. Note that you can connect to a service (and start it if it's not already running) with the Context.bindService ()
  10. 10. method. When connected to a service, you can communicate with it through an interface exposed by the service. For the music service, this might allow you to pause, rewind, etc. CONTENT PROVIDER Applications can store their data in files, an SQLite database, or any other mechanism that makes sense. A content provider, however, is useful if you want your application's data to be shared with other applications. A content provider is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider. Not every application needs to have all four, but your application will be written with some combination of these. All the components needed for android application should listed in an xml file called AndroidManifest.xml. This is an XML file where you declare the components of your application and what their capabilities and requirements are. Storing, Retrieving and Exposing Data A typical desktop operating system provides a common file system that any application can use to store and read files that can be read by other applications. Android uses a different system on Android, all application data are private to that application. However, Android also provides a standard way for an application to expose its private data to other applications. This section describes the many ways that an application can store and retrieve data, expose its data to other applications, and also how you can request data from other applications that expose their data. Android provides the following mechanisms for storing and retrieving data: Preferences A lightweight mechanism to store and retrieve key/value pairs of primitive data types. This is typically used to store application preferences. Files
  11. 11. You can store your files on the device or on a removable storage medium. By default, other applications cannot access these files. Databases The Android APIs contain support for SQLite. Your application can create and use a private SQLite database. Each database is private to the package that creates it. Content Providers A content provider is an optional component of an application that exposes read/write access to an application's private data, subject to whatever restrictions it wants to impose. Content providers implement a standard request syntax for data, and a standard access mechanism for the returned data. Android supplies a number of content providers for standard data types, such as personal contacts. Network Don't forget that you can also use the network to store and retrieve data. Security and Permissions in Android Android is a multi-process system, where each application (and parts of the system) runs in its own process. Most security between applications and the system is enforced at the process level through standard Linux facilities, such as user and group IDs that are assigned to applications. Additional finer-grained security features are provided through a "permission" mechanism that enforces restrictions on the specific operations that a particular process can perform, and per-URI permissions for granting ad-hoc access to specific pieces of data. System Architecture A central design point of the Android security architecture is that no application, by default, has permission to perform any operations that would adversely impact other applications, the
  12. 12. operating system, or the user. This includes reading or writing the user's private data such as contacts or e-mails, reading or writing another application's files, performing network access, keeping the device awake, etc. An application's process is a secure sandbox. It can't disrupt other applications, except by explicitly declaring the permissions it needs for additional capabilities not provided by the basic sandbox. These permissions it requests can be handled by the operating in various ways, typically by automatically allowing or disallowing based on certificates or by prompting the user. The permissions required by an application are declared statically in that application, so they can be known up-front at install time and will not change after that. Application Signing All Android applications (.apk files) must be signed with a certificate whose private key is held by their developer. This certificate identifies the author of the application. The certificate does not need to be signed by a certificate authority: it is perfectly allowable, and typical, for Android applications to use self-signed certificates. The certificate is used only to establish trust relationships between applications, not for wholesale control over whether an application can be installed. The most significant ways that signatures impact security is by determining who can access signature-based permissions and who can share user IDs. User IDs and File Access Each Android package (.apk) file installed on the device is given its own unique Linux user ID, creating a sandbox for it and preventing it from touching other applications (or other applications from touching it). This user ID is assigned to it when the application is installed on the device, and remains constant for the duration of its life on that device.
  13. 13. Using Permissions A basic Android application has no permissions associated with it, meaning it can not do anything that would adversely impact the user experience or any data on the device. To make use of protected features of the device, you must include in your AndroidManifest.xml one or more <uses-permission> tags declaring the permissions that your application needs. The permissions provided by the Android system can be found at Manifest.permission. Any application may also define and enforce its own permissions, so this is not a comprehensive list of all possible permissions. A particular permission may be enforced at a number of places during your program's operation: At the time of a call into the system, to prevent an application from executing certain functions. When starting an activity, to prevent applications from launching activities of other applications. Both sending and receiving broadcasts, to control who can receive your broadcast or who can send a broadcast to you. When accessing and operating on a content provider. Binding or starting a service Declaring and Enforcing Permissions To enforce your own permissions, you must first declare them in your AndroidManifest.xml using one or more <permission> tags. The <protection Level> attribute is required, telling the system how the user is to be informed of applications requiring the permission, or who is allowed to hold that permission, as described in the linked documentation.
  14. 14. The <permission Group> attribute is optional, and only used to help the system display permissions to the user. You will usually want to set this to either a standard system group (listed in android.Manifest.permission_group) or in more rare cases to one defined by yourself. It is preferred to use an existing group, as this simplifies the permission UI shown to the user. Note that both a label and description should be supplied for the permission. These are string resources that can be displayed to the user when they are viewing a list of permissions (android:label) or details on a single permission ( android:description). The label should be short, a few words describing the key piece of functionality the permission is protecting. The description should be a couple sentences describing what the permission allows a holder to do. Our convention for the description is two sentences, the first describing the permission, the second warning the user of what bad things can happen if an application is granted the permission. Development Process for Android Application To develop apps for Android devices, you use a set of tools that are included in the Android SDK. Once you've downloaded and installed the SDK, you can access these tools right from your Eclipse IDE, through the ADT plugin, or from the command line. Developing with Eclipse is the preferred method because it can directly invoke the tools that you need while developing applications. The basic steps for developing applications (with or without Eclipse) are shown in figure 1. The development steps encompass four development phases, which include: 1. Setup During this phase you install and set up your development environment. You also create Android Virtual Devices (AVDs) and connect hardware devices on which you can install your applications. 2. Development During this phase you set up and develop your Android project, which contains all of the source code and resource files for your application
  15. 15. 3. Debugging and Testing During this phase you build your project into a debuggable .apk package that you can install and run on the emulator or an Android-powered device. If you are using Eclipse, builds are generated each time you project is saved. If you're using another IDE, you can build your project using Ant and install it on a device using adb. 4. Publishing During this phase you configure and build your application for release and distribute your application to users.
  16. 16. 2. Introduction to Google Services for Android Developer Google APIs Console The Google APIs Console is a web interface for managing and viewing traffic data, authentication, and billing information for the Google APIs that are used by your project. In the APIs Console, a project is a named collection of information about your application: auth information, team members' email addresses, the Google APIs that your application uses, and so on. You can create your own projects, or be added as a viewer or editor to existing projects created by other developers. At the top of the Console is a dropdown list that shows the projects that you have access to, as well as commands for creating and managing projects The Console lets you see and manage the following project information: Activated APIs Activate one or more APIs to enable traffic monitoring, filtering, and billing, and API-specific pages for your project. Traffic information The Console reports traffic information for each activated API. Additionally, you can cap or filter usage by API. Project keys Each project is identified by either an API key or an OAuth 2.0 token. Use this key/token in your API requests to identify the project, in order to record usage data, enforce your filtering restrictions, and bill usage to the proper project. You can use the Console to generate or revoke API keys or OAuth 2.0 certificates to use in your application. Steps to enable API access 1. Open Google API console window with your Google account.
  17. 17. 2. Click on API Access and go to create new Android key, enter the SHA1 certificate Fingerprint. SHA1 certificate fingerprint accessed by the following command: keytool -list -v -keystore C:Usersleon.androiddebug.keystore -alias androiddebugkey -storepass android -keypass android It displays three keys SHA1, SHA2, MD5, user has to copy SHA1 key and paste it into configure android key window
  18. 18. 3. Now your API key is generated as shown below which can be used to access Google APIs.
  19. 19. 4. Now click on Services tap to activate various services provided by Google like Google map, Location API, calendar API etc. There are number of services available, enable the services which you want to use in your project . Services used in my project are: 5. Now with the help of your API key you can use activated services in your project. .
  20. 20. Google Maps Android v2 With the Google Maps Android API, you can add maps based on Google Maps data to your application. The API automatically handles access to Google Maps servers, data downloading, map display, and response to map gestures. You can also use API calls to add markers, polygons, and overlays to a basic map, and to change the user's view of a particular map area. These objects provide additional information for map locations, and allow user interaction with the map. The API allows you to add these graphics to a map: Icons anchored to specific positions on the map (Markers). Sets of line segments (Polylines). Enclosed segments (Polygons). Bitmap graphics anchored to specific positions on the map (Ground Overlays). Sets of images which are displayed on top of the base map tiles (Tile Overlays). Steps to use Google Map in Android Application: 1. Select File > Import > Android > Existing Android Code Into Workspace and click Next. 2. Select Browse..., enter <android-sdk- folder>/extras/google/google_play_services/libproject/google-play-services_lib, and click Finish. Once you have installed Google Play services, you can view the sample code, or run the sample app locally. The sample app is an Eclipse project that you can run on your device as follows: 1. Select File > Import > Android > Existing Android Code Into Workspace and click Next. 2. Select Browse..., enter <android-sdk- folder>/extras/google/google_play_services/samples/maps, and click Finish. 3. Select Project > Properties, select Java Build Path, and navigate to Libraries. 4. Select Add External Jars, include the following jar files, and click OK: + <android-sdk- folder>/extras/android/compatibility/v4/android-support-v4.jar 5. Add your own Google Maps Android API key. 6. Select Run > Run to test the sample app. The Map Object The Google Maps Android API allows you to display a Google map in your Android application. These maps have the same appearance as the maps you see in the Google Maps for Mobile
  21. 21. (GMM) app, and the API exposes many of the same features. Two notable differences between the GMM Application and the Maps displayed by the Google Maps Android API are: Map tiles displayed by the API don't contain any personalized content, such as personalized smart icons. Not all icons on the map are clickable. For example, transit station icons can’t be clicked. However, markers that you add to the map are clickable, and the API has a listener callback interface for various marker interactions. In addition to mapping functionality, the API also supports a full range of interactions that are consistent with the Android UI model. For example, you can set up interactions with a map by defining listeners that respond to user gestures. The key class when working with a Map object is the GoogleMap class. GoogleMap models the map object within your application. Within your UI, a map will be represented by either a MapFragment or MapView object. GoogleMap handles the following operations automatically: Connecting to the Google Maps service. Downloading map tiles. Displaying tiles on the device screen. Displaying various controls such as pan and zoom. Responding to pan and zoom gestures by moving the map and zooming in or out. In addition to these automatic operations, you can control the behavior of maps with objects and methods of the API. For example, Google Map has callback methods that respond to keystrokes and touch gestures on the map. You can also set marker icons on your map and add overlays to it, using objects you provide to Google Map. Google Direction API The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as
  22. 22. text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints. This service is generally designed for calculating directions for static (known in advance) addresses for placement of application content on a map; this service is not designed to respond in real time to user input, for example. For dynamic directions calculations (for example, within a user interface element), consult the documentation for the JavaScript API V3 Directions Service. Calculating directions is a time and resource intensive task. Whenever possible, calculate known addresses ahead of time (using the service described here) and store your results in a temporary cache of your own design. Direction Responses Directions responses are returned in the format indicated by the output flag within the URL request's path. 1. JSON Output 2. XML Output
  23. 23. 1. PROJECT DESCRIPTION AND OBJECTIVES Description: The Location Tracer and Automatic message sender Android Application is a travelling Application. Sometimes, we forget to inform our friends or our family that we have reached our destination and get busy with our work. This application helps users to set their destination and automatically will be sending to their friends or family that he reached his destination. This application also shows route in Google map from his source to destination. PROJECT OVERVIEW This android application has the following features: 1) It helps android users to get distance and time required to reach his destination 2) Automatic message will be send to the number set by the user when he reached his destination 3) Show your location on Google Map 4) Get Route from your source to destination Implementation This Android Application is implemented using following concepts 1) Retrieving current Location at every second 2) Retrieving Geo Coordinates of Destination 3) Read Contacts 4) Send SMS 5) Use Google Direction API 6) Google Maps android v2
  24. 24. 1. Retrieving the Current Location Location Services automatically maintains the user's current location, so all your app has to do is retrieve it as needed. The location's accuracy is based on the location permissions you've requested and location sensors that are currently active for the device. Location Services sends the current location to your app through a location client, which is an instance of the Location Services class LocationClientt. All requests for location information go through this client. Specify Application Permission: Apps that use Location Services must request location permissions. Android has two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. The permission you choose controls the accuracy of the current location. If you request only coarse location permission, Location Services obfuscates the returned location to an accuracy that's roughly equivalent to a city block. Requesting ACCESS_FINE_LOCATION implies a request for ACCESS_COARSE_LOCATION. For example, to add ACCESS_COARSE_LOCATION, insert the following as a child element of the <manifest>element: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> Create LocationManager instance as reference to the location service: For any background Android Service, we need to get reference for using it. Similarly, location service reference will be created using getSystemService() method. This reference will be added with the newly created LocationManager instance as follows. locationManager=(LocationManager)getSystemService(Context.Location_Ser vice); Request current location from Location Manager:
  25. 25. After creating the location service reference, location updates are requested using requestLocationUpdates() method of LocationManager. For this function, we need to send the type of location provider, number of seconds, distance and the LocationListener object over which the location to be updated. locationManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0, 0, this); Receive location update from Location Listener on change of location Location Listener will be notified based on the distance interval specified or the number seconds. It will return current latitude and longitude Geo coordinates to the user. Now we have current Geo Coordinates to compare with the destination coordinates.
  26. 26. 2. Retrieving Destination Geo Coordinates Geo Coordinates: A geographic coordinate system is a coordinate system that enables every location on the Earth to be specified by a set of numbers or letters. The coordinates are often chosen such that one of the numbers represents vertical position, and two or three of the numbers represent horizontal position. A common choice of coordinates is latitude, longitude and elevation. Geocoder Class: A class for handling geocoding and reverse geocoding. Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinates. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address. The amount of detail in a reverse geocoded location description may vary, for example one might contain the full street address of the closest building, while another might contain only a city name and postal code. The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists. Public Constructor for Geocoder class: public Geocoder (Context context, Locale locale); Method to retrieve Geo Coordinates from the given location we have to use public methods of Geocoder class Public Methods used: Public Methods List<Address> getFromLocation(double latitude, double longitude, int maxResults) Returns an array of Addresses that are known to describe the area immediately surrounding the given latitude and longitude.
  27. 27. List<Address> getFromLocationName(String locationName, int maxResults) Returns an array of Addresses that are known to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc.. Static boolean isPresent() Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented. Code used to extract Geo Coordinates of any location: protected Void doInBackground(Void... params) { try{ Geocoder coder = new Geocoder(MainActivity.this, Locale.getDefault()); list = coder.getFromLocationName(dest.getText().toString(), 1); } catch(Exception e){ Log.i("MO", "Exception"); } for (int i = 0; i < list.size(); i++) { Address add = list.get(i); lat = add.getLatitude(); lon =add.getLongitude(); } }
  28. 28. 3. Retrieving Contact List The Contacts Provider is the central repository of the user's contacts information, including data from contacts apps and social networking apps. In your apps, you can access Contacts Provider information directly by calling ContentResolvermethods or by sending intents to a contacts app. This class focuses on retrieving lists of contacts, displaying the details for a particular contact, and modifying contacts using intents. The basic techniques described here can be extended to perform more complex tasks. In addition, this class helps you understand the overall structure and operation of the Contacts Provider. To extract contact list from the android device, we have to add Read contact permission in the manifest file. <uses-permission android:name="android.permission.READ_CONTACTS" /> Steps to retrieve contact list: 1. Define fragment that display list of contacts To display the list of contacts, start by defining a Fragment that's loaded by an Activity. Using a Fragment is a more flexible technique, because you can use one Fragment to display the list and a second Fragment to display the details for a contact that the user chooses from the list. To help you write queries against the Contacts Provider, the Android framework provides a contracts class called ContactsContract, which defines useful constants and methods for accessing the provider. When you use this class, you don't have to define your own constants for content URIs, table names, or columns. To use this class, include the following statement: import android.provider.ContactsContract; Since the code uses a CursorLoader to retrieve data from the provider, you must specify that it implements the loader interface LoaderManager.LoaderCallbacks. Also, to help detect which contact the user selects from the list of search results, implement the adapter interface AdapterView.OnItemClickListener.
  29. 29. 2. Set up the Cursor Adapter for the list view Set up the SimpleCursorAdapter that binds the results of the search to the ListView. To get the ListViewobject that displays the contacts, you need to call Activity.findViewById() using the parent activity of theFragment. Use the Context of the parent activity when you call setAdapter(). mCursorAdapter = new SimpleCursorAdapter(getActivity(),R.layout.contact_list_item,null,0); mContactsList.setAdapter(mCursorAdapter); 3. Set the selected contact listener When you display the results of a search, you usually want to allow the user to select a single contact for further processing. For example, when the user clicks a contact you can display the contact's address on a map. To provide this feature, you first defined the current Fragment as the click listener by specifying that the class implements AdapterView.OnItemClickListener, as shown in the section Define a Fragment that displays the list of contacts. To continue setting up the listener, bind it to the ListView by calling the method setOnItemClickListener()in onActivityCreated() public void onActivityCreated(Bundle savedInstanceState) mContactsList.setOnItemClickListener(this); 4. Initialize the Loader Since we're using a CursorLoader to retrieve data, you must initialize the background thread and other variables that control asynchronous retrieval. Do the initialization in onActivityCreated(), which is invoked immediately before the Fragment UI appears. getLoaderManager().initLoader(0, null, this); after using loader class, we have to retrieve the contact number based on the contact_ID, if we have number of contact numbers of same person then we have to display all number into separate list and then select any one number from list.
  30. 30. 5. SMS in Android Development SMS is an integral part of mobile devices and mobile applications. An overwhelming majority of mobile users use the SMS service on their mobiles; some use it dozens of times per day. Android provides a very good API so that developers can integrate SMS technology into their apps, increasing the utility and appeal of their applications. In this article we are going to examine several apps that use SMS technology via the APIs provided by Android. Steps to send SMS from Android Application: 1. Create a UI (user interface) with two Edit Text element, one for Contact number and one for message which has to be send and one Button for sending SMS. UI for the app will look like as follows: 2. Specify the permissions for sending the SMS In Android, one has to specify all of the permissions needed by the app in the AndroidManifest.xml. By doing so while installing the app, all the permissions required by the app will be shown to the user.
  31. 31. <uses permission android:name="android.permission.SEND_SMS"></uses-permission> 3. Sending the SMS To send the SMS, we get the number and message text that the user entered. e text that Then, we get the SmsManager object as follows: SmsManager sms = SmsManager.getDefault(); 4. Displaying a Toast When the Message is Successfully Sent A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. Toast.makeText(getBaseContext(), "SMS sent",Toast.LENGTH_SHORT).show();
  32. 32. 5. Get Route by Direction API The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints. This service is generally designed for calculating directions for static (known in advance) addresses for placement of application content on a map; this service is not designed to respond in real time to user input, for example. For dynamic directions calculations (for example, within a user interface element), consult the documentation for the JavaScript API V3 Directions Service. Calculating directions is a time and resource intensive task. Whenever possible, calculate known addresses ahead of time (using the service described here) and store your results in a temporary cache of your own design. Directions Requests A Directions API request takes the following form: http://maps.googleapis.com/maps/api/directions/output?parameters where output may be either of the following values: json (recommended) indicates output in JavaScript Object Notation (JSON) xml indicates output as XML To access the Directions API over HTTPS, use: https://maps.googleapis.com/maps/api/directions/output?parameters HTTPS is recommended for applications that include sensitive user data, such as a user's location, in requests.
  33. 33. Request Parameters Certain parameters are required while others are optional. As is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below. Required parameters origin — The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. destination — The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. sensor — Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. Maps API for Business users must include valid client and signature parameters with their Directions requests. Please refer to the Maps API for Business Web Serviceschapter for more information. Screen Shots
  34. 34. 1. Set destination and contact number
  35. 35. 2. Other features
  36. 36. 3. Display Route from source to destination
  37. 37. 4. Display current location