Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial and Demos on Android in Virtual Box

Similar presentations


Presentation on theme: "Tutorial and Demos on Android in Virtual Box"— Presentation transcript:

1 Tutorial and Demos on Android in Virtual Box
CSC 4320/ Operating Systems Summer 2015

2 Outline Introduction of Android APP Development.
How to create an Android Virtual Machine? How to install the Eclipse Plugin for Android? Demo 1: Develop a Hello word App In Eclipse. Demo 2: A simple Process Manager App. Introduction of Android

3 Android App Development

4 Introduction Android is an open source and Linux-based operating system for mobile devices such as smartphones and tablet computers. Developed by the Open Handset Alliance, led by Google, and other companies. Apps are developed in the Java language using the Android Software Development Kit. First beta version of the Android Software Development Kit (SDK) was released by Google in 2007. First commercial version, Android 1.0, was released in September 2008. Current Android version - Android 5.0 "Lollipop”.

5 Android vs iOS Pros Cons Easy to program : Java based
Can be developed on any OS : Mac, Windows, Linux Cons Too many different types of devices to support Quality control

6 Android Architecture

7 Android Architecture 4 Layered Architecture Linux Kernel Libraries
Process management, memory management, device management Libraries SQLite database, web browser engine WebKit Android Runtime Dalvik Virtual Machine, kind of JVM optimized for Android Application Framework Provide high level services to applications like Telephony, Location Applications Android applications are written in this layer

8 Basic Components of Android Application
Activities Dictate the UI and handle the user interaction to the smartphone screen Services Handle background processing associated with an application. Broadcast Receivers Handle communication between Android OS and applications. Content Providers Handle data and database management issues.

9 Managing the Activity Lifecycle

10 Lifecycle methods onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy() Implementation of lifecycle methods is important because it ensures that application behaves well in following scenarios: Does not crash if the user receives a phone call or switches to another app while using your app. Does not consume valuable system resources when the user is not actively using it. Does not lose the user's progress if they leave your app and return to it at a later time. Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.

11 Development Environment Setup
Option 1 – Android Studio Step 1: Set up Java SDK Step 2: Android Studio Option 2 – Eclipse with ADT Step 2: Setup Android SDK Step 3: Setup Eclipse IDE Step 4: Setup Android Development Tools (ADT) Plugin

12 Testing the Android App
Run on Emulator – Android Virtual Device AVD Manager is used to configure a virtual device that models a specific device Run on real Android device Developer mode should enabled on the mobile device Run on an Android VM

13 How to create an android VM?

14 How to create an Android Virtual Machine?(1)
Download Android x-86 ISO from website Version: android-x r2.iso Install Android 4.4 using Virtual Box. Follow a tutorial in

15 How to create an Android Virtual Machine?(2)
The final screen after installing Android.

16 How to create an Android Virtual Machine?(4)
Remove the installing image disk from virtual drive.

17 How to create an Android Virtual Machine?(3)
Note: 1.Once you are in the Welcome screen, please disable the mouse integration so that the mouse cursor will be captured in screen. You can find the mouse integration button on the bottom of VM window.

18 How to create an Android Virtual Machine?(4)
Note: 2.If your Android system is in sleep mode (black screen) , please wake up it by sending shutdown signal through VM.

19 How to Install eclipse plug in for android?

20 How to install Eclipse Plugin for Android?
Install Eclipse plugin for Android Develop. Install the latest SDK tools and platform.

21 Install Eclipse plugin for Android Develop(1)
Steps Start Eclipse, then select Help > Install New Software. Click Add in the top-right corner. Enter “ADT Plugin” for the Name and following URL for the location.

22 Install Eclipse plugin for Android Develop(1)
Steps(continued) Click OK. In the available software dialog, select the checkbox next to Developer Tools and click Next. Follow the steps and Finish. Restart Eclipse.

23

24 Install the latest SDK tools and platform
Steps Open Eclipse Go to Window -> Open Perspective->Other and Select "Java" and click OK. Go to Window -> Android SDK Manager.

25 Install the latest SDK tools and platform
Steps(continued) Select packages “Tools”,“Android 4.4.2” and “Extras/Android Support Library” in the package list and click “Install packages”.

26 How to install Virtual Machine?(2)
Install the latest SDK tools and platform. Select packages “Tools” and “Android 4.4.2” in the package list and click “Install packages”.

27 Install the latest SDK tools and platform
Steps(continued) Accept the licenses for those package and click install.

28 Install the latest SDK tools and platform.
Accept the licences for those package and click

29 Install the latest SDK tools and platform
Steps(continued) Then wait for about ten to fifteen minutes.

30 Install the latest SDK tools and platform
Check installed SDK in Eclipse. Go to Eclipse -> Preferences -> Android Check SDK installed in the Target List. (Note: if the target list is empty, please click “Browse” and select the path for folder “android-sdk” )

31 Install the latest SDK tools and platform

32 Demo 1 : Develop a Hello word App In Eclipse.

33 Demo 1 Configure the connection between Eclipse and Android VM.
Open VM VirtulBox Manager. Select Android VM and click the property Network. In Adapter 1, change network adapter attached to “Bridge Adapter”. Click “Advanced” and for “Promiscuous Mode” please select “Allow All”. Click Ok and finish the setting.

34 Demo 1 Configure the connection between Eclipse and Android VM(continued). Open Android VM. Open Terminal Emulator. Type netcfg Check the IP address for eth0. E.g

35 Demo 1 Configure the connection between Eclipse and Android VM(continued). For Windows OS: Add a new system variable Computer -> Advanced System Setting -> Environment Variables ->New(User Variables) Variable Name: “ADB” Variable Value: “;<Path of adb.exe >” Open command window Type command: adb connect Note: is the IP address of Android VM.

36 Demo 1 Configure the connection between Eclipse and Android VM(continued). For MacOS: Add a new system variable Open a terminal Type $open ~./profile In the popped window, add the following text at end of text file. export PATH=$PATH:<path of adb.> export PATH=$PATH:/Users/yuanlong/Documents/MacOS_Shared/Project/P2/Eclipse_workspace/android-sdk-macosx/platform-tools Close terminal and reopen it Type command: adb connect Note: is the IP address of Android VM.

37 Demo 1 Create a simple Android app. Eclipse -> New -> Other
Select Android Application Project, click “Next” Enter Application Name, e.g. HelloWorldAPP Keep the default settings for other options. Follow the steps and finish.

38

39 Demo 1 Important Files Activity_main.xml
Default file for XML layout file for the activity. Provides both text view and preview of the screen UI. MainActivity.java Java code for activity class that gets executed when application is run. AndroidManifest.xml Presents essential information about your app to the Android system like components, java package, permissions. Strings.xml Contains all the text that your application uses.

40 Demo 1 src Contains the java class and application logic.
MainActivity.java Java code for activity class that gets executed when application is run.

41 Demo 1 gen Contains automatically generated java files by ADT. Do not modify. R.java An index to all the resources in “res” folder.

42 Demo 1 assets Store data files. E.g. XML files.

43 Demo 1 bin Executable files. *.apk
Android application package for install application in Android OS. (For debugging.)

44 Demo 1 res Contains resources, e.g. images(drawable folder), layout, strings(values folder).

45 Demo 1 Code for showing process ID Open activity_main.java
Add an id for the component TextView. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" /> Open MainActivity.java Type the following statements at the end of onCreate(). int id= android.os.Process.myPid(); TextView text = (TextView) findViewById(R.id.textViewHello); text.setText("Current Procee ID :"+Integer.toString(id));

46 Demo 1 Code for debugging Open MakeActivity.java
Add the following instructions at the end of function OnCreate(). Log.d("Process ID:",Integer.toString(id));

47 Demo 1 Generate APK file and install it in Android VM Debugging
Right click your project -> Run Appliacation -> Run as Android Application Debugging Eclipse -> Window -> Show View -> Other Type “logcat” Select Logcat The print outs are stored in log info.

48 Demo 2: A simple Process Manager App.

49 Demo 2 A simple Process Manager List the processes in Android System.
Displaying the traffic statistics. See more at

50 Demo 2 A simple Process Manager
See more at

51 Demo 2 Layout design (res/layout/activity_main.xml) Linear layout
Image Text <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="APP NAME GOES HERE" /> </LinearLayout>

52 Demo 2 Building a list for processes
Create a file ListAdapter.java under src. Import following packages. import java.util.List; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView;

53 Demo 2 Building a list for processes(continues)
Let ListAdapter extends ArrayAdapter<RunningAppProcessInfo> Create a constructor for ListApdapter. public class ListAdapter extends ArrayAdapter<RunningAppProcessInfo> { // List context private final Context context; // List values private final List<RunningAppProcessInfo> values; public ListAdapter(Context context, List<RunningAppProcessInfo> values) { super(context, R.layout.activity_main, values); this.context = context; this.values = values; }

54 Demo 2 Building a list for processes(continues)
Override method getView() @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.activity_main, parent, false); TextView appName = (TextView) rowView.findViewById(R.id.appNameText); appName.setText(values.get(position).processName); return rowView; }

55 Demo 2 Display process list and show traffic statistics
Modify src/MainActivity.java Extends class ListActivity Modify OnCreate() so that once app is open all the processes are listed. Override OnListItemClick() so that once an item in the list is clicked the traffic statistics will be displayed.

56 Demo 2 Display process list and show traffic statistics
Imported Packages import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.ListActivity; import android.net.TrafficStats; import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.widget.Toast;

57 Demo 2 Display process list and show traffic statistics
Definition of MainActivity.java public class MainActivity extends ListActivity { }

58 Demo 2 Display process list and show traffic statistics
Override OnCreate() @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get running processes ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses(); if (runningProcesses != null && runningProcesses.size() > 0) { // Set data to the list adapter setListAdapter(new ListAdapter(this, runningProcesses)); } else { // In case there are no processes running (not a chance :)) Toast.makeText(getApplicationContext(), "No application is running", Toast.LENGTH_LONG).show(); }

59 Demo 2 Display process list and show traffic statistics
Override OnListItemClick() @Override protected void onListItemClick(ListView l, View v, int position, long id) { long send = 0; long recived = 0; // Get UID of the selected process int uid = ((RunningAppProcessInfo)getListAdapter().getItem(position)).uid; // Get traffic data recived = TrafficStats.getUidRxBytes(uid); send = TrafficStats.getUidTxBytes(uid); // Display data Toast.makeText(getApplicationContext(), "UID " + uid + " details...\n send: " + send/ "kB" + " \n recived: " + recived/ "kB", Toast.LENGTH_LONG).show(); }

60 Demo 2 Generate corresponding APK file and install it to Android VM.

61 Useful Resources 1. 2. 3. 4. 5. “Android Tablet Application Development For Dummies” By Gerhard Franken 6. The following is a link for installing Eclipse Android Development plug in.

62 Q&A


Download ppt "Tutorial and Demos on Android in Virtual Box"

Similar presentations


Ads by Google