Académique Documents
Professionnel Documents
Culture Documents
Agenda
Introduction Mobile Devices Profile Mobile Software Option For Development
Introduction
Mobile application development is the process by which application software is developed for small lowpower handheld devices such as personal digital assistants, enterprise digital assistants or mobile phones. These applications are either pre-installed on phones during manufacture, or downloaded by customers from various mobile software distribution platforms.
Mobile Applications
One of the primary considerations in creating mobile applications for your business is the type of the application. This requires an understanding of the different options available in building mobile applications. Mobile applications can be built as: Native applications (or) Web/browser applications.
Native applications
A native mobile application is a piece of software for Smartphones and tablets.
These applications are built specifically for each mobile platform and are installed on the device. The application is specifically designed to run on the devices operating system and machine firmware. Native applications can be built as: Device specific applications These applications are developed using proprietary or device specific languages/tools like Objective C, Android SDK, Blackberry SDK etc.
Multiplatform applications - These applications can be deployed on different devices using the same codebase. Frameworks like Rhodes, Phone Gap, Mother App etc. are used in building these applications.
Web applications
These applications are designed for use on specific Smartphones or Tablets and are accessed through the devices web browser (Safari, Internet Explorer, etc). Each time an application is run on the device, all or some parts of the software is downloaded from the Web.
Since mobile web applications are accessed through the browser without requiring installation on each device, they are platform independent.
The key difference between the above mentioned application types is that
Performance- Web applications largely depend upon the browsers performance. The browser resides between the application and the OS. If the browser is not functioning well, the performance of the web application will also be affected and will go slow
But in the case of Native Applications, all the screens load instantly. If the screen depends upon dynamic data from the server, the complete screen comes up first and the data is loaded as-synchronously i.e. in background. The advantage here is that the users will not have to wait for the UI to load. Limited Device Feature Access - Web applications run on browsers and hence may miss out on many very useful features such as access to the Photo library, the Address book, the Camera, the Accelerometer, the Music Library, Voice recording, device specific data etc. Alerts - Native Applications can accommodate alerts using which the user can be notified for future tasks. Alerts cannot be accommodated in Web Applications.
Data Management - Web Applications support offline SQL databases and the records are stored locally. This will reduce performance when compared to native applications as the browser would communicate with the local database and with multiple tabs open, the speed of the application would go down. Also, if the browser data is cleared, all local data would be deleted, thus affecting the performance of the web application.
Android is a software bunch comprising 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.
Android is a powerful Operating System supporting a large number of applications in smart phones.
Hardwares that support Android are mainly based on ARM architecture platform.
Android is available as open source for developers to develop applications which can be further used for selling in android market.
Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver
Development Environment
A software development kit that enables developers to create applications for the Android platform.
The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications.
Applications are written using the Java programming language and run on Dalvik, a custom virtual machine designed for embedded use which runs on top of a Linux kernel. Virtual Machine is a self-contained operating environment that behaves as if it is a separate computer
Step1:
You need to install jdk and suitable version of eclipse. The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.
Step 2:
Download the sdk starter package.
that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application.
1.Start Eclipse, then select Help > Install New Software....
https://dl-ssl.google.com/android/eclipse/ 4.Click OK 5. In the Available Software dialog, select the checkbox next to Developer Tools and click Next. 6.In the next window, you'll see a list of the tools to be downloaded. Click Next. 7.Read and accept the license agreements, then click Finish. 8.When the installation completes, restart Eclipse.
On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute:android
Install a Platform
To install a platform in Eclipse: In the Android SDK and AVD Manager, choose Available Packages in the left panel.
In the right panel, expand the Android Repository list to display the components available for installation.
Select at least one platform to install, and click Install Selected. If you aren't sure which platform to install, use the latest version.
Create an AVD
An AVD defines the system image and device settings used by the emulator. To create an AVD:
Type the name of the AVD, such as "my_avd". Choose a target. The target is the platform (that is, the version of the Android SDK, such as 2.3.3) you want to run on the emulator. For this tutorial, choose the latest platform that you have installed and ignore the rest of the fields.
Fill in the project details with the following values: Project name: HelloAndroid Build Target: Select a platform version that is equal to or lower than the target you chose for your AVD.
Your Android project is now ready. It should be visible in the Package Explorer on the left. Open the HelloAndroid.java file, located inside HelloAndroid > src > com.example.helloandroid). It should look like this: package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {
AVDs let you define certain hardware aspects of your emulated phone and allow you to create many configurations to test many Android platforms and hardware permutations. Once your application is running on the emulator, it can use the services of the Android platform to invoke other applications, access the network, play audio and video, store and retrieve data, notify the user, and render graphical transitions and themes.
The Android emulator is a QEMU-based application that provides a virtual ARM mobile device on which you can run your Android applications. It runs a full Android system stack, down to the kernel level, that includes a set of preinstalled applications (such as the dialer) that you can access from your applications.
You can choose what version of the Android system you want to run in the emulator by configuring AVDs, and you can also customize the mobile device skin and key mappings. When launching the emulator and at runtime, you can use a variety of commands and options to control its behaviors.
The Android system image distributed in the SDK contains ARM machine code for the Android Linux kernel, the native libraries, the Dalvik VM, and the various Android package files (such as for for the Android framework and preinstalled applications).
The emulator's QEMU layers provide dynamic binary translation of the ARM machine code to the OS and processor architecture of your development machine.
Emulator Limitations
No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however. No support for USB connections No support for camera/video capture (input). No support for device-attached headphones No support for determining connected state No support for determining battery charge level and AC charging state
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. The Android SDK provides most of the tools that we need to debug your applications.
We need a JDWP-compliant debugger if we want to be able to do things such as step through code, view variable values, and pause execution of an application. In Eclipse, a JDWP-compliant debugger is already included and there is no setup required.
The main components that comprise a typical Android debugging environment are
:
Android Debug Bridge (adb) Dalvik Debug Monitor Server Device or Android Virtual Device
1.A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients. 2.A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device. 3.A daemon, which runs as a background process on each emulator or device instance. You can find the adb tool in <sdk>/platform-tools/.
User interface
The user interface, in the design field of human machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the machine which aids the operator in making operational decisions. A user interface is the system by which people (users) interact with a machine. The user interface includes hardware (physical) and software (logical) components.
User interfaces exist for various systems, and provide a means of:
Input, allowing the users to manipulate a system Output, allowing the system to indicate the effects of the users' manipulation In an Android application, the user interface is built using View and ViewGroup objects. There are many types of views and view groups, each of which is a descendant of the View class.
View objects are the basic units of user interface expression on the Android platform. The View class serves as the base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons.
A View object is a data structure whose properties store the layout parameters and content for a specific rectangular area of the screen. As an object in the user interface, a View is also a point of interaction for the user and the receiver of the interaction events. On the Android platform, you define an Activity's UI using a hierarchy of View and ViewGroup nodes
Agenda
Activity Life cycle Creating the Activity An overview of user interfaces Using XML layouts Selection Widgets The Web view & the Web Kit Browser Dialogue Boxes: Alert Dialogue & Toast Using Resources
Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View) There are two methods almost all subclasses of Activity will implement:
1.onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.
2. onPause( ) is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data). All activity classes must have a corresponding <activity> declaration in their package's AndroidManifest.xml. The Activity class is an important part of an application's overall lifecycle, and the way activities are launched and put together is a fundamental part of the platform's application model.
Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.
An activity has essentially four states:
1. If an activity in the foreground of the screen (at the top of the stack), it is active or running.
2. If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system
4.If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.
For example, you can register a BroadcastReceiver in onStart() to monitor for changes that impact your UI, and unregister it in onStop() when the user an no longer see what you are displaying. The onStart() and onStop() methods can be called multiple times, as the activity becomes visible and hidden to the user.
3.The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all other activities and interacting with the user. An activity can frequently go between the resumed and paused states -- for example when the device goes to sleep, when an activity result is delivered, when a new intent is delivered -- so the code in these methods should be fairly lightweight.
To create an activity, you must create a subclass of Activity(or an existing subclass of it).
In your subclass, you need to implement callback methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed.
onPause( );
...
</application ... > ... </manifest > There are several other attributes that you can include in this element, to define properties such as the label for the activity, an icon for the activity, or a theme to style the activity's UI. An <activity> element can also specify various intent filters using the <intent-filter> elementin order to declare how other application components may activate it.
When you create a new application using the Android SDK tools, the stub activity that's created for you automatically includes an intent filter that declares the activity responds to the "main" action and should be placed in the "launcher" category.
The intent filter looks like this: <activity android:name=".ExampleActivity" android:icon="@drawable/app_icon"> <intent-filter>
</intent-filter>
</activity> The <action> element specifies that this is the "main" entry point to the application. The <category> element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).
View objects are the basic units of user interface expression on the Android platform.
The View class serves as the base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons.
The ViewGroup class serves as the base for subclasses called "layouts," which offer different kinds of layout architecture, like linear, tabular and relative. A View object is a data structure whose properties store the layout parameters and content for a specific rectangular area of the screen. A View object handles its own measurement, layout, drawing, focus change, scrolling, and key/gesture interactions for the rectangular area of the screen in which it resides As an object in the user interface, a View is also a point of interaction for the user and the receiver of the interaction events.
So a <TextView> element creates a TextView in your UI, and a <LinearLayout> element creates a LinearLayout view group.
Do so by calling setContentView(), passing it the reference to your layout resource in the form of: R.layout.layout_file_name
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout);}
Selection Widget
A widget is a View object that serves as an interface for interaction with the user. Android provides a set of fully implemented widgets, like buttons, checkboxes, and text-entry fields, so you can quickly build your UI. Some widgets provided by Android are more complex, like a date picker, a clock, and zoom controls. But you're not limited to the kinds of widgets provided by the Android platform. If you'd like to do something more customized and create your own actionable elements, you can, by defining your own View object or by extending and combining existing widgets
Layout XML[optional]- An optional XML file inside res/layout/ that describes the layout of your widget. You could also do this in code in your Java file.
It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more. To enable the built-in zoom, set WebSettings.setBuiltInZoomControls(boolean)
In order for your Activity to access the Internet and load web pages in a WebView, you must add the INTERNET permissions to your Android Manifest file: <uses-permission android:name="android.permission.INTERNET" />
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView android:id="@+id/web_engine"
android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
<intent-filter>
<action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCH ER"/> </intent-filter>
</activity>
</application>
</manifest>
The typical alert dialog provides information in a separate box to the user, after which the user can only respond in one way: by closing it. Closing an alert dialog will provide access to the original window, which is not available while the alert dialog is presented.
A Toast is a view containing quick little message for the user.
When the toast view is shown to the user, appears as a floating view over the application.
Toast will never receive focus
Creating an AlertDialog
An Alert Dialog is an extension of the Dialog class.
You should use it for dialogs that use any of the following features:
1.A title 2.A text message 3.One or two buttons 4.A list of selectable items (with optional checkboxes or radio buttons)
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.this.finish(); } })
Instantiate a Toast object with one of the makeText() methods This method takes three parameters: the application Context, the text message, and the duration for the toast. You can display the toast notification with show() Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();
.
.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } });
Using Resources
Resources in Android are files stored under the res directory of your project. Resources can be physical files (Audio, video, images, text, etc) or xml files that declare some values to use in your application
.
Why use Resources: The resources are bound to the application in a way that you can change them without needing to change the source code or recompile the application.
The Android Generates an ID for each resource file so you can access them directly and easily. All the resources IDs are added to the R.Java file.
When you use XML resource files, Android pareses these files automatically so you can reference values defined in them directly with no extra effort. Using resources is very useful in Localization and Internationalization of the application in case you develop multilingual applications. This includes not just the labels but it can include alignment, directions images or any kind of files.
Types of resources:
Strings, colors, arrays, dimensions. Defined in res/values/ directory. Using them is very useful in Localization and Internationalization.
Images put in res/drawable directory. You can put all the images or icons you need in your application. XML, defined in res/xml/ directory for xml files containing your custom data. Layout resources, defined in res/layout/ for declaring the views that construct the user interface of the activities.
Agenda
Working with Intent Classes Building a service Communication
Intent objects passed to any of the broadcast methods (such as Context.sendBroadcast(), Context.sendOrderedBroadcast(), or Context.sendStickyBroadcast()) are delivered to all interested broadcast receivers.
An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity).
Building a service
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Each service class must have a corresponding <service> declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService(). Services can be started with Context.startService() and Context.bindService().
Note that services, like other application objects, run in the main thread of their hosting process.
This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work.
The IntentService class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.
Communication
Here is a sample activity that will invoke a service
,
/**
* this is the main activity - File Scanner
* @author sschauhan
*/
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //just pass the reference to the service FileScannerService.setMainActivity(this); //creating an intent for the service
{
//start the service
startService(fileScannerService);
//remove or hide the app
Finish();
}});
//stop button
Button btnStop = (Button) findViewById(R.id.btn_stop); //on click of stop button btnStop.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //stop the service stopService(fileScannerService); //remove or hide the app
finish(); } });}
The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network.
There is a simple way to make requests to web services and APIs (and plain html pages if you want).
We can also post values on server using HttpClient. The class uses the org.apache.http library which is included in Android.
public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php" ); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("id", "12345"));
// Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } }
Make request using HttpClient: AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println(response); } });
You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings.
This data will persist across user sessions (even if your application is killed).
To get a SharedPreferences object for your application, use one of two methods:
getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter. getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.
To write values: 1.Call edit() to get a SharedPreferences.Editor. 2.Add values with methods such as putBoolean() and putString().
// Commit the edits! editor.commit(); // Restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
Content Providers
Content providers store and retrieve data and make it accessible to all applications. They're the only way to share data across applications; there's no common storage area that all Android packages can access. Android ships with a number of content providers for common data types (audio, video, images, personal contact information, and so on). You can see some of them listed in the android.provider package.
You can then use the ContentResolver's methods to interact with whatever content providers you're interested in.
When a query is initiated, the Android system identifies the content provider that's the target of the query and makes sure that it is up and running. The system instantiates all ContentProvider objects;
The interaction between processes is handled by the ContentResolver and ContentProvider classes.
// Make the query. Cursor managedCursor = managedQuery(contacts, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection arguments (none) // Put the results in ascending order by name People.NAME + " ASC"); // retreiving values using cursor name = cur.getString(nameColumn); // Add Abraham Lincoln to contacts and make him a favorite. values.put(People.NAME, "Abraham Lincoln");
Multimedia
The Android multimedia framework includes support for capturing and playing audio, video and images in a variety of common media types, so that you can easily integrate them into your applications.
You can play audio or video from media files stored in your application's resources, from standalone files in the file system, or from a data stream arriving over a network connection, all using the MediaPlayer or JetPlayer APIs.
You can also record audio, video and take pictures using the MediaRecorder and Camera APIs if supported by the device hardware.
player.stop(); player.reset();
player.release();
player = null;
Thankyou