Avnesh File android

Embed Size (px)

Citation preview

  • 8/15/2019 Avnesh File android

    1/27

    Candidate Declaration

    This is to certify that Report entitled “Android Google Maps App” which is submitted by me

    in partial fulfillment of the requirement for the award of degree B.Tech. in Computer Science

    and Engineering to DAV University, Jalandhar ( Pb.) comprises only my work and dueacknowledgement has been made in the text to all other material used.

    Avnesh Sharma

    Btech.CSE

    11300424

    i

  • 8/15/2019 Avnesh File android

    2/27

    ACKNOWLEDGEMENT

    I express my sincere gratitude to my concerned teacher and guide Er.Harpreet Singh ,

    Assistant Professor, Department of CSE, for his valuable and inspiring guidance towards the

     progress on the topic “Android Google Maps App” and providing valuable information for

    the development of my report.

    Last but not the least I express my sincere and hearty thanks to all those who have directly or

    indirectly helped me in completing this seminar presentation and report successfully.

    i

  • 8/15/2019 Avnesh File android

    3/27

    ABSTRACT

    This is a project report on –“Android Google Maps Application”. During the developing of

    this project we exploit, new ideas and functionality behind the working of a AndroidStudio.Android Studio is an Official tool for developing Android apps.

    This project is the output of our planning, schedule, programming skill and the hard work,

    and this report reflects our steps taken at various levels of programming skill, planning and

    schedule. We have leant a lot during this project and liked the improvement in our testing

    skills and deep concept related to these kinds of projects.

    Android Google Maps Application is a mobile based Android application which helps to

    find certain locations.

    iii

  • 8/15/2019 Avnesh File android

    4/27

      TABLE OF CONTENTS

    TITLE PAGE NO.

    Candidate's Declaration................................................................................................................................i 

    Acknowledgement........................................................................................................................................ii

    Abstract........................................................................................................................................................iiiTable of Contents.........................................................................................................................................iv

    List of Figures...............................................................................................................................................v

    Chapter 1 

    1. INTRODUCTION .................................................................................................................... 1

    Chapter 2 

    2. Features of Android OS............................................................................................................... 2

    Chapter 3 

    3.1 Android Architecture................................................................................................................. 3 

    3.1.1 Application Framework.............................................................................................. 4 

    3.1.2 Android Runtime.........................................................................................................5 

    3.1.3 Linux Kernel...............................................................................................................6 Chapter 4 

    4.1 Lifecycle of an Android Application .......................................................................................7-9

    4.2 Security and Permissions in Android.......................................................................................10

     4.3 Development tools.....................................................................................................................11-12

    Chapter 5 

    5.1About Project ............................................................................................................................13-20 Conclusion ............................................................................................................................................. 21 References ..............................................................................................................................................22

     

    i

  • 8/15/2019 Avnesh File android

    5/27

     

    LIST OF FIGURES

    FIGURE 1: Architecture of Android OS................................................................................................3

    FIGURE 2: Conversion from .java to .dex file.......................................................................................5

    FIGURE 3: Android Activity Life Cycle...............................................................................................9

    v

  • 8/15/2019 Avnesh File android

    6/27

     Chapter 1

    1. INTRODUCTION 

    Android is the first complete, open, and free mobile platform. Developers enjoy a comprehensive softw

    development kit, with ample tools for developing powerful, feature-rich applications. The platform is op

    source, relying on tried-and-true open standards developers will be familiar with. And best of all, there are

    costly barriers to entry for developers: no required fees. (A modest fee is required to publish on third-pa

    distribution mechanisms such as the Android Market.) Android developers have numerous options

    distributing and commercializing their applications.

    In 2008, the Open Handset Alliance announced the Android platform and launched a beta program

    developers. Android went through the typical revisions of a new platform. Several prerelease revisions of Android Software Development Kit (SDK) were released. The first Android handset (the T-Mobile G1) be

    shipping in late 2008. Throughout 2009, more Android handsets and diverse types of devices powered

    Android reached world markets. As of this writing, there are more than 36 Android phones available fr

    carriers around the world. This number does not include the numerous Android tablet and e-book readers a

    available, nor the dozens of upcoming devices already announced, nor the consumer electronics running Andro

    The rate of new Android devices reaching the world markets has continued to increase. In the United States,

    major carriers now include Android phones in their product lines.

    Google has been a contributing member of the Open Handset Alliance from the beginning. The company ho

    the Android open source project as well as the Android developer program at http://developer.android.com. T

    developer website is your go-to site for downloading the Android SDK, getting the latest platfo

    documentation, and browsing the Android developer forums. Google also runs the most popular service

    selling Android applications to end users: the Android Market.

    Cheap and Easy Development 

    If there’s one time when “cheap and easy” is a benefit, it’s with mobile development. Wireless applicat

    development, with its ridiculously expensive compilers and preferential developer programs, has been notoriou

    expensive to break into compared to desktop development. Here, Android breaks the proprietary mold. Unl

    with other mobile platforms, there are virtually no costs to developing

    Android applications.The Android SDK and tools are freely available on the Android develo

    website,http://developer.android.com.

  • 8/15/2019 Avnesh File android

    7/27

     

    Chapter 2

    2. Features of Android OS

      Application framework enabling reuse and replacement of components 

      Dalvik virtual machine optimized for mobile devices 

      Integrated browser based on the open source WebKit engine 

      Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the Open

    ES 1.0 specification (hardware acceleration optional)

      SQLite for structured data storage 

     

    Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC

    AMR, JPG, PNG, GIF)

      GSM Telephony (hardware dependent) 

      Bluetooth, EDGE, 3G, and WiFi (hardware dependent) 

      Camera, GPS, compass, and accelerometer (hardware dependent) 

     

    Rich development environment including a device emulator, tools for debugging, memory an performance profiling, and a plugin for the Eclipse IDE

  • 8/15/2019 Avnesh File android

    8/27

     

    Chapter 3

    3.1 Android Architecture 

    The following diagram shows the major components of Android

    Figure 1: Architecture of Android OS

  • 8/15/2019 Avnesh File android

    9/27

     

    3.1.1 Application Framework 

    Developers have full access to the same framework APIs used by the core applications. The application

    architecture is designed to simplify the reuse of components; any application can publish its capabilities and

    any other application may then make use of those capabilities (subject to security constraints enforced by

    the framework). This same mechanism allows components to be replaced by the user.

    Underlying all applications is a set of services and systems, including:

      A rich and extensible set of Views that can be used to build an application, including lists,

    grids, text boxes, buttons, and even an embeddable web browser

      Content Providers that enable applications to access data from other applications (such as

    Contacts), or to share their own data

      A Resource Manager, providing access to non-code resources such as localized strings

    graphics, and lat files

      A Notification Manager that enables all applications to display custom alerts in the status bar

      An Activity Manager that manages the life cycle of applications and provides a common

    navigation backstack

  • 8/15/2019 Avnesh File android

    10/27

     

    3.1.2 Android Runtime 

    Android includes a set of core libraries that provides most of the functionality available in the core

    libraries of the Java programming language. Every Android application runs in its own process, with its

    own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs

    efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for

    minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language

    compiler that have been transformed into the .dex format by the included "dx" tool. The Dalvik VM relies

    on the Linux kernel for underlying functionality such as threading and low-level memory management.

    At the same level there is Android Runtime, where the main component Dalvik Virtual Machine is located

    It was designed specifically for Android running in limited environment, where the limited battery, CPU,

    memory and data storage are the main issues. Android gives an integrated tool “dx”, which converts

    generated byte code from .jar to .dex file, after this byte code becomes much more efficient to run on the

    small processors.

    Figure 2: Conversion from .java to .dex file

    As the result, it is possible to have multiple instances of Dalvik virtual machine running on the

    single device at the same time. The Core libraries are written in Java language and contains of the

    collection classes, the utilities, IO and other tools.

  • 8/15/2019 Avnesh File android

    11/27

     

    3.1.3 Linux Kernel 

    Android Architecture is based on Linux 2.6 kernel. It helps to manage security, memory managem

     process management, network stack and other important issues. Therefore, the user should bring Linux in

    mobile device as the main operating system and install all the drivers required in order to run it. Android provi

    the support for the Qualcomm MSM7K chipset family. For instance, the current kernel tree supports Qualcom

    MSM 7200A chipsets, but in the second half of 2008 we should see mobile devices with stable vers

    Qualcomm MSM 7200, which includes major features:

    1. WCDMA/HSUPA and EGPRS network support

    2. Bluetooth 1.2 and Wi-Fi support

    3. Digital audio support for mp3 and other formats

    4. Support for Linux and other third-party operating systems

    5. 

    Java hardware acceleration and support for Java applications

    6. Qcamera up to 6.0 megapixels

    7.  gpsOne –  solution for GPS

  • 8/15/2019 Avnesh File android

    12/27

     

    Chapter 4

    4.1 Lifecycle of an Android Application 

    In most cases, every Android application runs in its own Linux process. This process is created for

    application when some of its code needs to be run, and will remain running until it is no longer needed and  

    system needs to reclaim its memory for use by other applications.

    An important and unusual feature of Android is that an application process's lifetime is not   dire

    controlled by the application itself. Instead, it is determined by the system through a combination of the parts

    the application that the system knows are running, how important these things are to the user, and how mu

    overall memory is available in the system.

    It is important that application developers understand how different application components (in particu

    Activity, Service, and IntentReceiver) impact the lifetime of the application's process. Not using these

    components correctly can result in the system killing the application's process while it is doing important

    work.

    A common example of a process life-cycle bug is an IntentReceiver that starts a thread when it receives

    Intent in its onReceiveIntent() method, and then returns from the function. Once it returns, the system consid

    that IntentReceiver to be no longer active, and thus its hosting process no longer needed (unless other applicat

    components are active in it). Thus, it may kill the process at any time to reclaim memory, terminating

    spawned thread that is running in it. The solution to this problem is to start a Service from the IntentReceiver,

    the system knows that there is still active work being done in the process.

    To determine which processes should be killed when low on memory, Android places them into

    "importance hierarchy" based on the components running in them and the state of those components. These a

    in order of importance:

    1. 

    A foreground process is one holding an Activity at the top of the screen that the user is interactwith (its onResume () method has been called) or an IntentReceiver that is currently running (its onReceiveInt

    () method is executing). There will only ever be a few such processes in the system, and these will only be kil

    as a last resort if memory is so low that not even these processes can continue to run. Generally at this point

    device has reached a memory paging state, so this action is required in order to keep the user interface respons

  • 8/15/2019 Avnesh File android

    13/27

    2.  A visible process  is one holding an Activity that is visible to the user on-screen but not in

    foreground (its onPause() method has been called). This may occur, for example, if the foreground activity has

     been displayed with a dialog appearance that allows the previous activity to be seen behind it. Such a proces

    considered extremely important and will not be killed unless doing so is required to keep all foreground proces

    running.

    3.  A service process  is one holding a Service that has been started with the startService() meth

    Though these processes are not directly visible to the user, they are generally doing things that the user ca

    about (such as background mp3 playback or background network data upload or download), so the system w

    always keep such processes running unless there is not enough memory to retain all foreground and visi

     process.

    4.  A background process is one holding an Activity that is not currently visible to the user (its onSto

    method has been called). These processes have no direct impact on the user experience. Provided they implem

    their activity life cycle correctly (see Activity for more details), the system can kill such processes at any time

    reclaim memory for one of the three previous processes types. Usually there are many of these processes runni

    so they are kept in an LRU list to ensure the process that was most recently seen by the user is the last to be kil

    when running low on memory.

    5.  An empty process  is one that doesn't hold any active application components. The only reason

    keep such a process around is as a cache to improve startup time the next time a component of its applicat

    needs to run. As such, the system will often kill these processes in order to balance overall system resour between these empty cached processes and the underlying kernel caches.

    When deciding how to classify a process, the system picks the most important level of all the componen

    currently active in the process.

  • 8/15/2019 Avnesh File android

    14/27

     

    Figure 3:Android Activity Life Cycle 

  • 8/15/2019 Avnesh File android

    15/27

     

    4.2 Security and Permissions in Android 

    Android is a multi-process system, where each application (and parts of the system) runs in its o

     process. Most security between applications and the system is enforced at the process level through stand

    Linux facilities, such as user and group IDs that are assigned to applications. Additional finer-grained secu

    features are provided through a "permission" mechanism that enforces restrictions on the specific operations t

    a particular process can perform.

    Android mobile phone platform is going to be more secure than Apple’s iPhone or any other device in

    long run. There are several solutions nowadays to protect Google phone from various attacks. One of them

    security vendor McAfee, a member of Linux Mobile (LiMo) Foundation. This foundation joins particucompanies to develop an open mobile-device software platform. Many of the companies listed in the Li

    Foundation have also become members of the Open Handset Alliance (OHA).

    As a result, Linux secure coding practice should successfully be built into the Android developm

     process. However, open platform has its own disadvantages, such as source code vulnerability for black-

    hackers. In parallel with great opportunities for mobile application developers, there is an expectation

    exploitation and harm. Stealthy Trojans hidden in animated images, particular viruses passed from friend

    friend, used for spying and identity theft, all these threats will be active for a long run.

    Another solution for such attacks is SMobile Systems mobile package. Security Shield  – an integra

    application that includes anti-virus, anti-spam, firewall and other mobile protection is up and ready to run on

    Android operating system. Currently, the main problem is availability for viruses to pose as an application and

    things like dial phone numbers, send text messages or multi-media messages or make connections to the Inter

    during normal device use. It is possible for somebody to use the GPS feature to track a person’s location with

    their knowledge. Hence SMobile Systems is ready to notify and block these secure alerts. But the truth is that i

    not possible to secure r mobile device or personal computer completely, as it connects to the internet. And neit

    the Android phone nor other devices will prove to be the exception.

  • 8/15/2019 Avnesh File android

    16/27

     

    4.3 Development Tools 

    The Android SDK includes a variety of custom tools that help develop mobile applications on the Andr

     platform. The most important of these are the Android Emulator and the Android Development Tools plugin

    Eclipse, but the SDK also includes a variety of other tools for debugging, packaging, and installing r applicatio

    on the emulator.

    Android Emulator 

    A virtual mobile device that runs on computer use the emulator to design, debug, and test r applications in

    actual Android run-time environment.

    Android Studio 

    Android Studio is the official IDE for Android application development, based on IntelliJ IDEA. Otop of

    capabilities you expect from IntelliJ, Android Studio offers:

    Flexible Gradle-based build system

    Build variants and multiple apk  file generation

    Code templates to help you build common app features

    Rich layout editor with support for drag and drop theme editing

    Android Debug Bridge (adb) 

    The adb tool lets install application's .apk files on an emulator or device and access the emulator or device from

    command line. can also use it to link a standard debugger to application code running on an Android emulator

    device.

    Android Asset Packaging Tool (aapt) 

    The aapt tool lets create .apk files containing the binaries and resources of Android applications.

    https://www.jetbrains.com/idea/https://www.jetbrains.com/idea/https://www.jetbrains.com/idea/

  • 8/15/2019 Avnesh File android

    17/27

     

    Android Interface Description Language (aidl) 

    Aidl Lets generate code for an interprocess interface, such as what a service might use.

    SQLITE 

    Included as a convenience, this tool lets access the SQLite data files created and used by Android applications.

    Trace view 

    This tool produces graphical analysis views of trace log data that can generate from r Android application.

    mksdcard 

    Helps create a disk image that can use with the emulator, to simulate the presence of an external storage ca

    (such as an SD card).

    dx 

    The dx tool rewrites .class bytecode into Android bytecode (stored in .dex files.)

    activityCreator 

    A script that generates Ant build files that can use to compile r Android applications. If are developing on

    Eclipse with the ADT plugin, won't need to use this script.

  • 8/15/2019 Avnesh File android

    18/27

    0Chapter 5

    5.1 ABOUT PROJECT

    Project:Google Maps Application

    Android allows us to integrate google maps in our application. You can show any location on the map , or c

    show different routes on the map e.t.c. You can also customize the map according to your choices.

    Adding Google Map

    Google provides this facility using google play services library which you have to download externally. Af

    downloading, you have to integrate it with your project.In the end you have to integrate your application w

    google via google console. This is completely discussed in the example.

    Google Map - Activity file

    Google provides GoogleMap and MapFragment api to integrate map in your android application. In order to u

    GoogleMap , you have to create an object of GoogleMap and get the reference of map from the xml lay

    file.The code is given below:

    GoogleMap googleMap;

    googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    Google Map - Layout file

     Now you have to add the map fragment into xml layout file.

  • 8/15/2019 Avnesh File android

    19/27

    Google Map - AndroidManifest file

    The next thing you need to do is to add some permissions along with the Google Map API key in t

    AndroidManifest.XML file.

    Customizing Google Map

    You can easily customize google map from its default view , and change it according

    your demand.

    Adding Marker

    You can place a maker with some text over it displaying your location on the map. It c

    be done by via addMarker() method.

    final LatLng TutorialsPoint = new LatLng(21 , 57);

    Marker TP = googleMap.addMarker(new MarkerOptions().position(TutorialsPoint).title("TutorialsPoint"));

  • 8/15/2019 Avnesh File android

    20/27

    Changing Map Type

    You can also change the type of the MAP. There are four different types of map and each give different view

    the map. These types are Normal,Hybrid,Satellite and terrain. You can use them as below

    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

    googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

    Enable/Disable zoom

    You can also enable or disable the zoom gestures in the map by calli

    thesetZoomControlsEnabled(boolean) method.

    googleMap.getUiSettings().setZoomGesturesEnabled(true);

  • 8/15/2019 Avnesh File android

    21/27

    Here is an example demonstrating the use of GoogleMap class. It creates a basic

    application that allows you to navigate through the map.

    To experiment with this example , you can run this on an actual device or in

    emulator.Following steps are needed to be implemented.

    1 Integrate google maps in your application.

    2 You will use Android studio to create an Android application under a packa

    com.example.sairamkrishna.myapplication. While creating this project, make sure you Target SDK and Comp

    With at the latest version of Android SDK to use higher levels of APIs.

    3 Modify src/MainActivity.java file to add necessary code.

    4 Modify the res/layout/activity_main to add respective XML components

    5 Modify AndroidManifest.xml to add necessary internet permission

    6 Run the application and choose a running android device and install the application on it and verify

    results

    Obtaining the API key

    This part is further divided into two steps. First you have to get an SHA1 fingerprint k

    from your pc and then you have to get map API key from google console.

  • 8/15/2019 Avnesh File android

    22/27

    Coding And Implementation:

    MainActivity

    public class MainActivity extends Activity {

    static ArrayList places;

    static ArrayAdapter arrayAdapter ;

    static ArrayList locations;

    @Overrideprotected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout. activity_main);

    ListView listView = (ListView) findViewById(R.id.listView);

     places = new ArrayList();

     places.add("Add a new place...");

    locations = new ArrayList();

    locations.add(new LatLng(31.4221,75.6173));

    Log.i("Places", places.toString());

    arrayAdapter = new ArrayAdapter(this, android.R.layout. simple_list_item_1, places);

    listView.setAdapter(arrayAdapter );

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Overridepublic void onItemClick(AdapterView parent, View view, int position, long id) {

    Intent i = new Intent(getApplicationContext(), MapsActivity.class);i.putExtra("locationInfo", position);

    startActivity(i);

    }

    });

    }

  • 8/15/2019 Avnesh File android

    23/27

     

    MapsActivity.java

    public class MapsActivity extends FragmentActivity implements GoogleMap.OnMapLongClickListener,LocationListener {

    private GoogleMap mMap;

    int location = -1;

    LocationManager locationManager;

    String provider;

    private GoogleApiClient client;

    @Overridepublic void onMapLongClick(LatLng point) {

    Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault ());

    String label = new Date().toString();

    try {

    List listAddresses = geocoder.getFromLocation(point.latitude, point.longitude, 1);

    if (listAddresses != null && listAddresses.size() > 0){

    label = listAddresses.get(0).getAddressLine(0);

    }

    } catch (IOException e) {

    e.printStackTrace();

    }

    MainActivity. places.add(label);

    MainActivity.locations.add(point);

    mMap.addMarker(new MarkerOptions()

    .position(point)

    .title(label)

    .icon(BitmapDescriptorFactory.defaultMarker (BitmapDescriptorFactory. HUE_RED)));}

    @Overrideprotected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

  • 8/15/2019 Avnesh File android

    24/27

      setContentView(R.layout. activity_maps);

    locationManager = (LocationManager) getSystemService(Context. LOCATION_SERVICE);

    provider = locationManager.getBestProvider(new Criteria(), false);

    ActionBar actionBar = getActionBar();

    actionBar.setDisplayHomeAsUpEnabled(true);

    Intent i = getIntent();location = i.getIntExtra("locationInfo", 1);

    setUpMapIfNeeded();

    client = new GoogleApiClient.Builder(this).addApi(AppIndex. API ).build();

    }

    @Overrideprotected void onPause() {

    super.onPause();

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission. ACCESS_FINE_LOCATION ) !=

    PackageManager. PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,

    Manifest.permission. ACCESS_COARSE_LOCATION ) != PackageManager. PERMISSION_GRANTED){ 

    return;

    }locationManager.removeUpdates(this);

    }

    private void setUpMapIfNeeded() {

    if (mMap == null) {

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id. map))

    .getMap();

    mMap.setOnMapLongClickListener(this);.if (mMap != null) {

    setUpMap();

    }

    }}

    @Override

    public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

  • 8/15/2019 Avnesh File android

    25/27

      case android.R.id. home:if (ActivityCompat.checkSelfPermission(this, Manifest.permission. ACCESS_FINE_LOCATION ) !

    PackageManager. PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,

    Manifest.permission. ACCESS_COARSE_LOCATION ) != PackageManager. PERMISSION_GRANTED) {

    }

    locationManager.removeUpdates(this);

    this.finish();return true;

    default:return super.onOptionsItemSelected(item);

    }

    }

    Activity_maps.xml

  • 8/15/2019 Avnesh File android

    26/27

     

    CONCLUSION

    Android is a truly open, free development platform based on Linux and open source. Handset makers can u

    and customize the platform without paying a royalty.

    A component-based architecture inspired by Internet mash-ups. Parts of one application can be used in anoth

    in ways not originally envisioned by the developer can even replace built-in components with own improv

    versions. This will unleash a new round of creativity in the mobile space.

      Android is open to all: industry, developers and users

      Participating in many of the successful open source projects

      Aims to be as easy to build for as the web.

      Google Android is stepping into the next level of Mobile Internet

  • 8/15/2019 Avnesh File android

    27/27

     

    REFERENCES 

    1.  White paper for “A Spectrum White Paper: Thoughts on Google Android” from Spectrum data

    Technology.  http://www.spectrumdt.com

    2.  http://code.google.com/android/ - Google Android official webpage

    3.  http://www.openhandsetalliance.com/ - Open Handset Alliance webpage

    4.  http://en.wikipedia.org/wiki/Android_(mobile_phone_platform) – Wikipedia information

    5.  http://googleblog.blogspot.com/ - Official Google Blog

    http://www.spectrumdt.com/http://www.spectrumdt.com/