Sunday, October 15, 2017

1.1 INTRODUCTION

Less than two years ago, Google released a preliminary version of the development kit Android, its new OS dedicated to smartphones. Futurists and fans were split between immediately excited and skeptical. Detractors, in particular, have always seen in Android an experiment, and not something real to which device manufacturers would have believed. To help them deposed the fact that, for quite a long time, nobody smartphone equipped with Android was the terminus on the market, although the system and its development tools were been available for some time. The technique of Google, in fact, was and still is the as always: in the mouth-watering (and be talked about) with pre-release versions of its software and its services.
 In the case of Android, many developers have been loyal and get excited about a system who at that time was not yet on the market. In the meantime, things have changed: Android has been consolidated, and many mobile device manufacturers have already joined or are Alliance led by Google.
 Thanks to the strategies of Google, there is already a large community of developers, extremely production, which other mobile systems can not match. Thousands of applications have already been developed, and many more will be in the near future.
 The system is also robust and has very large potential. For this reason, from the number you are reading, I plan to devote a course Android programming series.
 It begins, of course, with the study of the system architecture, installation and the use of development tools, a first overview on the basic principles of Android programming and the development of a first simple application like “Hello World”.

1.2 HOW IS THAT ANDROID

Android, being a modern operating system invoice, is quite complex. Although her targets are mobile, the architecture of Android has little to envy to those of the common systems for desktop or laptop.
 As can be seen from the figure, Google has drawn freely from the Open Source world. The heart of every system, Android, to begin with, is a Linux kernel, version 2.6. Are inserted directly into the kernel driver to control the hardware of the device: drivers for the keyboard, screen, touchpad, Wi-Fi, Bluetooth, audio and control so on. Above the kernel lean the main libraries, these all borrowed from Open Source world. Worth mentioning are certainly OpenGL for graphics, SQLite, for data management, and WebKit, to display Web pages short, over the next months we will have to discuss that!
 The architecture also provides for a virtual machine and a foundation library, which together constitute the development platform for Android apps. This virtual machine called Dalvik, and is substantially a Java Virtual Machine. As will verify later, some of the characteristics of Dalvik and its library will not allow you to immediately identify the platform Java available in Android with one of those Reference (Java SE, Java ME).
 In the penultimate layer of the architecture can be traced operators and applications base of the system. There are handlers for resources, for installed applications, for phone calls, the file system, and more, all components that you can hardly do without. Finally, the top layer of the architecture, standing on the applications for the user final. Many, of course, are already included with the basic installation: the browser and the multimedia player are easy examples. At this level also will fit applications that, together, we will learn to develop over the course of this series.

1.3 ANDROID SKD

To develop applications that can run on Android systems, you must install on your PC a special development kit (SDK), should be complete emulator, libraries, and documentation. If you have already developed for platforms such as Java ME or Windows Mobile, you know exactly what we want (but if you do not ve never done it, do not worry: well cover here). The first good news is that The Android SDK is available free of charge and without discrimination for Windows, Linux and MacOS X. As a start, its not bad.

You can download the application at:


http://developer.android.com/sdk/


You will be asked to download the most recent version available. Go ahead to download
the package for your system. The installation of the kit is very simple.
The only thing you have to make sure, before you do, is to meet the basic requirements.

In particular, it is required that the system already has a Java SDK (JDK) version 5
or later. It is absolutely necessary to meet this requirement, since Android is
program in Java, and without a JDK is not possible to compile the code. After checking
requirements, you can proceed. Take the ZIP file downloaded from the Internet and unzip
where you prefer. Its all: the Android SDK is ready to use! At most you can improve the installation adding to the PATH environment variable of the operating system the path to the folder that is inside the Android SDK tools. Doing so will be more simply invoke the executable from the command line kit. The operation, however, not is essential for a proper functioning of the kit. In this course, in addition, we will to serve as little as possible of the command line, although on some occasions will return useful if not essential.

1.4 ADT FOR ECLIPSE

Although Android SDK have scripts that automate application installation, launch the emulator and debug the code, work in an integrated environment, with every option at your fingertips, its definitely easier.
Especially when the integrated environment called Eclipse. The site of Andr oid contacted pr ecedenza
there is also a plug-in for the popular open source development platform. This
add-on called Android Development Tools for Eclipse, which becomes abbreviated ADT.

The module works with the latest versions of Eclipse, which are 3.3, 3.4 and also the new
3.5. It can be installed directly from within the development platform.
Start Eclipse and run the wizard to install new components. In Eclipse
3.5 it is done with the menu item Help Install New Software. In 3.4 the menu item Help
Software Updates, and then you have to select the tab Available Software. In Eclipse 3.3, finally,
the menu item to invoke is Help» Software Updates »Find and install, then choosing
Search for new features to install. Once delivered, choose the option to add
a new remote site to the list of sources presented by the wizard (Add button). The address
to specify is:


https://dl-ssl.google.com/android/eclipse/r


At this point, select the entry for the new source and proceed through the individual
steps of the wizard. The plug-in for the development of Android software will be automatically downloaded
and installed. After restarting Eclipse, go immediately to the preferences screen
environment (menu item Window Preferences ).

Here you will find the new category Android in the list on the left.
Select it and set the path to your Android SDK is necessary so that Eclipse can
hook the development kit. During this phase you should also get a pop-up
accettadella the license of the plug-in.

For now you can ignore the other settings related to the plug-in: we will learn
to use them later, when we are more familiar with the environment.

1.5 MANAGEMENT ADV

The development kit includes an emulator that will allow us to test our creations on your PC before you install them on a real device equipped with Android. To develop applications, then we must learn to interact with this emulator. The first concept is that you must assimilate what name has Android Virtual Device (AVD), ie virtual Android device. In our PC we can create and configure as many virtual devices want. Its like having many different
smartphone to use for their own tests, only instead of plastic devices and
Silicon is the VM that is made of pure software, to be made through
the emulator. In this way it is also possible to start simultaneously on the same
PC two or more virtual devices, for example to test an application that interact
most smartphones, such as a chat or a multiplayer game. Then learn to manage
the list of configured virtual devices in our Android SDK. You can manage them
command line, using the command android is in the tools folder of the SDK, but
use management interface made available from ADT in Eclipse will make the operation
certainly easier. Activate the menu item Window Android AVD Manager .

The window shows the list of configured virtual devices (initially empty) and
mask for creating a new instance. We use this opportunity and create the
Our first AVD. The items to be filled in are:

  
• Name: The name you want to assign to the virtual device, such as Android1.
  
• Target: the type of the device. Choose Android 1.5. We will create such a device
tive virtual compatible with version 1.5 of the specifications of Android.
  
• SD Card: Here you can equip the dispositi vo virtual card virtual memory.
You can either specify the path to an image file of a card to me
memory, if you want to reuse the existing virtual memory resistant, is a dimension of
space, to create a new virtual memory. We follow this road and
specific name is the value 64M. This creates a virtual memory card of 64 MB.
  
• Skin: you can choose from the rice solution of the device. The choices
are HVGA-P (equivalent to 480x320), HV GA-L (320x480), QVGA-P (320x240) and QVGAL
(240x320). Then there is a default choice simply called HVGA, which corresponds
shores anyway HVGA-P. Leave selected wheel.


After setting these values, confirm the operation by pressing the Create AVD.
The new virtual device will join the list managed by the manager, and now
can be used to debug and test applications.

1.6 LET THE EMULATOR

If youre new to using Android,
before you start programming it is better that you take confidence. Exploring applications
base so you can get a view of the system, to learn the principles of operation
design and its applications.

You can start a virtual device outside of Eclipse, just to do a round
reconnaissance. With the command prompt to the directory tools kit
development. Launch now a command like:


@ NomeAVD emulator


A NomeAVD must be replaced by a name which, in the course of the preceding paragraph, you
assigned to the virtual device created.


For example: @ Android1 emulator


A few moments of patience (on the first throw a little bit more) and the emulator will load
and make available the Android virtual device, in all its splendor. With the
mouse, you can simulate the touchpad device, clicking on the screen. Let
Take a tour and well acquainted with the environment. First of all have fun with
basic applications, such as the browser or the heading will help a lot in understanding
the principles of use of the system. Then move on to the more technical material: the main menu
contains the Dev Tools, which contains a set of tools dedicated to those Android
want to program, not just us for a test drive. Among these was the terminal emulator,
that allows to have a system shell for an interaction of the lowest level
with the device.

1.7 HELLO WORLD, ANDROID

The time has come to use ADT and the emulator to program our first Android application.
 Of course it will be a variation on the classic Hello, World. Start Eclipse. With ADT you have time for a new project category called Android Project. Create a project of this tipo.Nel project creation wizard use the configuration that is shown below:

     • Project name: CiaoMondoandroid
     • Build target: select Android 1.5.
     • Application name: Hello World
     • Package name: it.programmo.helloandroid
     • CreateActivity: CiaoMondoandroidActivity

 The project, at this point, can be created by pressing the button Finish.
 Eclipse will automatically populate the project, by inserting libraries Android and the basic structure plans for this platform. In a burst of generosity, Eclipse will also provide creation of the first class of the solution, called CiaoMondoandroidActivity (as specified under Create Activity) and included in the package it.programmo.hello Android (like the Package name). Open the class code and modify it the following way:

 it.programmo.helloandroid package
 import android.app.Activity
 import android.os.Bundle
 import android.widget.TextView
 public class extends Activity {CiaoMondoandroidActivity
     @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState)
         TextView tv = new TextView (this);
         tv.setText (Hello World Android!)
         setContentView (tv)
     }
 }

 Now select the project root CiaoMondoandroid, activate the context menu to right and launch the Run As Android Application .
 The emulator is loaded. Eclipse will automatically install inside the application CiaoMondoandroid and then start as soon as the operation is complete. Its done: your first software for Android is running in front of your eyes.

Subsequently, by accessing the run configurations (menu item Run Run Configurations
in Eclipse 3.5 and 3.4, Run Open Run Dialog in Eclipse 3.3), you can alter the
parameters and start the emulator application. This included the virtual device on
which will install and start the software. We recommend that you do some experiments.

Try, for example, to create different AVD, so by testing the software with screens of different
size and proportions. Another interesting experiment, which I recommend to make
before proceeding any further, is to use the Eclipse debugger with the Android app. Place a
breakpoint on the class made and start again emulator and application, this time in
debug mode.

1.8 LIBRARIES AND DALVIK ANDROID

After the test the first Android project, back to take care of the fundamental concepts for programming in this environment. As we have learned and demonstrated, the development platform is Java nature. However, it This is a particular platform and personalized, worth investigating.
 The virtual machine called Dalvik, seems to be a Java Virtual Machine, but in reality it is not entirely. We will explain better: a Java Virtual Machine executes bytecode code, right? Here, the Dalvik Virtual Machine bytecode does not standard, but another language, called DEX (Dalvik Executable), specifically designed for better performance in a smartphone. With the Android SDK and Eclipse, however, we seem to use a regular Java Virtual Machine. The development environment, in fact, it automatically the code generation DEX, re-compiling the bytecode which in turn is the result of a first common Java compilation. We will be completely transparent. This peculiarity of Dalvik, therefore, will not affect the way we plan. The same consideration, instead, can not be made regarding the basic library that supports Dalvik. Open the document to the path docs / reference / packages.html in your Android SDK. It is the index of Java packages including in the core library.
 Scorretela quickly and draw the first conclusions as well. There is a lot of Standard Edition Java, but there is everything. For example, there are AWT and Swing. The core packages, however, are all there, and appear largely identical to how they want to really just comes from Sun Micro Edition, virtually nothing.
 The Java ME platform has been snubbed by Android, which has preferred more like a library to that of a desktop system. Then do not go unnoticed by the many package prefix Android which, of course, are unique to this particular platform. Serve for the interaction directly with the capabilities of the underlying system.
 For example: the package android.widget contains the custom components of Android for the construction of graphical user interfaces (in CiaoMondoAndroid we used TextView) in android.graphics package are the primitive functions for graphics lower level, in android.location there are the tools to interact with any GPS receiver including the device.
 Each of Android packages, of course, deserves an extended discussion and complete many are the possible fields of application. What emerges is a profile of a platform development complex, because it is very rich, but simple, neat and because it shares deal with the issue of traditional Java.
 The Board, of course, is to always keep on hand documentation of Android API. Let yourself be guided by your curiosity then: give also a first look at classes more that tickle your fancy.

1.9 PRINCIPLES OF PROGRAMMING

About program with Java ME MIDlet knows that are the fundamental building block of MIDP applications, those who create Web applications with Java EE is not can not ignore what is a Servlet, even less experienced programmers know that applications Java, to run in a browser, should be factored into an Applet.
 All this to say that each environment, Java and features of its basic building blocks, that the developer can extend and implement in order to find a point of engagement with the platform. Android is no exception, in fact amplifies it. Depending on what you want to do is available a different model. Android provides four basic building blocks:

     • Activities: The activities are those blocks of an application that interact with the user using the screen and input devices available from your smartphone. Commonly make use of ready-made UI components, such as those found in the package android.widget, but this is not necessarily the rule. The class demonstration CiaoMondoandroidActivity is an activity. The activities are probably the model most popular in Android, and come to extending the base class android.app.Activity.
     • Service: A service runs in the background and does not directly interact with the user. For example, can play an MP3 track, while you use the activities to another. A service is realized by extending the class android.app.Service.
     • Broadcast Receiver: A Broadcast Receiver is used when you want to catch a particular event, throughout the system. For example you can use if you want to make action when a picture is taken or when the low battery reporting. The class to extend is android.content.BroadcastReceiver.
     • Content Provider: The Content Provider is used to expose data and information. Form a channel communication between different applications installed on your system. It can create a Content Provider extending the abstract class android.content.ContentProvider.

 An Android application consists of one or more of these elements. Very frequently, contains at least one activity, but it is said that it must always be so.

1.10 APK PACKAGES

Android applications are distributed under form of APK (Android Package). They are collected in executable format DEX, any associated resources and a series of descriptors that delineate the contents of the package. In particular, the so-called manifesto, are declared activities, services, provider and receiver of the package so that the system can engage them and operate them properly.
 Let us, in Eclipse, the project CiaoMondoAndroid. Inside youll find a file called
AndroidManifest.xml, made as follows:


<? Xml version = 1.0 encoding = utf-8?>

<Manifest xmlns: android = http://schemas.android.com/apk/res/android
  
package = it.programmo.helloandroid
  
Android: versionCode = 1
  
Android: versionName = 1.0>
  
<application android:icon=@drawable/icon android:label=@string/app_name>
  
<activity android:name=.CiaoMondoAndroidActivity android:label=@string/app_name>
      
<intent-filter>
          
<action android:name=android.intent.action.MAIN />
          
<category android:name=android.intent.category.LAUNCHER />
      
</Intent-filter>
  
</Activity>
  
</Application>
  
<uses-sdk android:minSdkVersion=3 />

</Manifest>


It is obvious descriptor mentioned earlier. Inside you can and should declare the components
of your software. Eclipse, when building the project, has already run on it some
initial configurations.

For example recorded the activity CiaoMondoAndroidActivity, specified properties
general application and also generate and set an icon for our program
(Res / drawable / icon.png). Of course, these choices can be altered, and new components
can be added to the project.

The special visual editor made available by the Eclipse, you will find it all very simple:
just do a little practice and deepen each time the appearance of interest. Once the work is complete, you can export the APK file to distribute to lucky owners of an Android system. Before deploying around the package, however, is must affix a digital signature on it. Otherwise, Android can not install the content.
 This is the only constraint imposed by the system. The fact that a packet should be signed not to worry about the developer: It is not necessary that a certification authority recognizes the key used for signing. Consequently, it is possible to sign a package APK also using a certificate homemade. Simply put: do not no pay because our software are authorized, we can do everything ourselves. In Eclipse, once again, is a matter of one click: open the context menu on the root of the project (right-click in Windows) and choose Android Tools
»Export Signed Application Package.
 At the second step of the wizard for generating the package, you will be asked where to take the digital signature. Usually the objects of this type are collected and stored in a keystore. In a keystore, ie, there are more digital signatures. If you have never formed a keystore before, or if they simply want to start a new one, select the option Create new keystore.
 The keystore is stored in a file whose path must be specified. Choose where to store the keystore directory is C: keystores) and give a name to your liking to file (android_keystore, if image). There is no need to use a particular extension for the file name. However, it is good practice protect your keystore with a password, so that our digital signatures can not be used in case someone steals the file. Therefore, take care Set a password safe enough.
 As the newly created keystore is empty, the next step of the wizard lets us create a key, ie a digital signature. We have to enter the name of the key (called aliases), the password to use the key, a validity in years (usually using the value 25) and data personal base of the petitioner (name).
 After the phase of creation or selection of the keystore and key, the wizard is to choose where to save the APK package that will be generated. Choose your destination and finish the operation.
 It is made: the packet was generated and signed. You can now install it on a device Android real, plastic, metal and silicon.

Categories

Unordered List

Disini

Sample Text

Powered by Blogger.

Pages

Popular Posts

Recent Posts

Text Widget