Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vijay Kumar Kolagani Dr. Yingcai Xiao

Similar presentations


Presentation on theme: "Vijay Kumar Kolagani Dr. Yingcai Xiao"— Presentation transcript:

1 Vijay Kumar Kolagani Dr. Yingcai Xiao
Android Vijay Kumar Kolagani Dr. Yingcai Xiao

2 Introduction 2003, Blackberry introduced first widely used smart phone. Smart phone OS dominated by android and iPhone. Android was initially developed by Android, Inc. Acquired by google in 2005. 2007, development taken over by Open Handset Alliance. Open source, written in a form of java, using an XML tag set for the displays.

3 ANDROID Development Tools

4 Development Tools Android software are developed with IDEs (Integrated Development Environment). We will use Android Studio: You can also use Eclipse for Android developers: You also need two development toolkits: Java Development Kit (JDK) Android Development Toolkit (ADT) included in Android Studio and Eclipse for Android.

5 ANDROID STUDIO SETUP

6 Setup Android Studio Android studio : Download the dmg file and open it to install. Select standard installation. Start Android Studio. It may check and update latest Android SDK. For the very first time you run the application, you will be asked to select a screen configuration.

7 Setup Android Studio

8 PROGRAMMING with android studio

9 Programming with Android Studio
Start Android Studio Import an Android code sample Select an existing sample (say, Universal Music Player). Update any components when asked to do so. Run->Run. Select Deployment Target Connected Devices or Virtual Devices It will automatically deploy the app to the device you selected and run it there.

10 Programming with Android Studio

11 DEPLOY ANDROID APP

12 Programming with Android Studio
You can also create build an APK file to distribute. Build->Build APK(s) Update any components when asked to do so. A prompt screen will show up when done building for you to locate and analyze the APK. C:\Users\xiao\AndroidStudioProjects\UniversalMusicPlayer\mobile\build\outputs\apk\mobile- debug.apk it to yourself. On your phone, save the attachment from your gmail. The app will be automatically installed.

13 Vysor interacting with your phone on a computer

14 Vysor: interacting with your phone on a computer
To interact with your Android phone on a computer, download Vysor. You can download it for Windows, Mac, Linux or Chrome For windows, you also need to download ADB

15 Vysor: interacting with your phone on a computer
On your Android phone: Settings Develop options (if your don’t see the options, go to “About Phone”, click “Build number” several times until it says you are now a developer. :-). Turn on USB Debugging USB configuration: Select MTP (Media Transfer Protocol)

16 Vysor: interacting with your phone on a computer
Connect you phone to the computer’s USB port. You computer should automatically detects the phone and prompt you to start Vysor. If not, start Vysor youself. Select the device to view. If Vysor does not detect you device, do the following: Make sure your USB cable is the original data cable not just a charging cable. Restart you computer and restart your phone. If still not working, remove and reinstall Vysor and ADB.

17 Vysor

18 ANDROID INPUT DEVICES

19 Android Interactions Voice Control Touch Screen Sensor Control

20 Sensors Overview The Android platform supports three broad categories of sensors: Motion sensors: these sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. Environmental sensors: these sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. This category includes barometers, photometers, and thermometers. Position sensors: these sensors measure the physical position of a device. This category includes orientation sensors and magnetometers.

21 Android EDP CODING

22 Identifying sensors and sensor capabilities.
Basic programming tasks: Identifying sensors and sensor capabilities. Identify sensor events to monitor. Write handlers for them.

23 Sensor Framework The sensor framework is part of the android.Hardware package and includes the following classes and interfaces: Sensormanager You can use this class to create an instance of the sensor service. This class provides various methods for accessing and listing sensors, registering and unregistering sensor event listeners, and acquiring orientation information. This class also provides several sensor constants that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors. Sensor You can use this class to create an instance of a specific sensor. This class provides various methods that let you determine a sensor's capabilities. Sensorevent The system uses this class to create a sensor event object, which provides information about a sensor event. A sensor event object includes the following information: the raw sensor data, the type of sensor that generated the event, the accuracy of the data, and the timestamp for the event. Sensoreventlistener You can use this interface to create two callback methods that receive notifications (sensor events) when sensor values change or when sensor accuracy changes.

24 Identifying sensors and sensor capabilities
Create an instance of the sensormanager class by calling the getsystemservice() method and passing in the sensor_service argument. We can determine whether A specific type of sensor exists on A device by using the getdefaultsensor() method and passing in the type constant for A specific sensor for example: private SensorManager mSensorManager; ... mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); if (mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null){ // Success! There's a Accelerometer. } else { // Failure! No Accelerometer. }

25 Monitoring Sensor Events
To monitor raw sensor data you need to implement two callback methods that are exposed through the sensoreventlistener interface: onaccuracychanged() and onsensorchanged() this methods are called whenever the following occurs: A sensor's accuracy changes. In this case the system invokes the onaccuracychanged() method, providing you with a reference to the sensor object that changed and the new accuracy of the sensor. Accuracy is represented by one of four status constants SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_MEDIUM,SENSOR_STATUS_ACCURACY_HIGH, or SENSOR_STATUS_UNRELIABLE. A sensor reports a new value. In this case the system invokes the onsensorchanged() method, providing you with a sensorevent object. A sensorevent object contains information about the new sensor data, including: the accuracy of the data, the sensor that generated the data, the timestamp at which the data was generated, and the new data that the sensor recorded.

26 An example using Accelerometer
Accelerometer measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. This example uses the Accelerometer to roll a group of balls.

27 An example using Accelerometer
Accelerometer_Android Studio Project Directory \app\src\main\java\com\example\android\accelerometerplay AccelerometerPlayActivity.java Public void onsensorchange(sensorevent sensorevent) {     sensor mysensor = sensorevent.Sensor;     If (mysensor.Gettype() == sensor.Type_accelerometer) {         float x = sensorevent.Values[0];         Float y = sensorevent.Values[1];         Float z = sensorevent.Values[2];     } }

28 An example using Accelerometer
Accelerometer_Android Studio Project Directory \app\src\main\java\com\example\android\accelerometerplay AccelerometerPlayActivity.java Public void onsensorchange(sensorevent sensorevent) {     sensor mysensor = sensorevent.Sensor;     If (mysensor.Gettype() == sensor.Type_accelerometer) {         float x = sensorevent.Values[0];         Float y = sensorevent.Values[1];         Float z = sensorevent.Values[2];     } }

29 Converting Unity3D Games to Android Apps

30 CODE Modification Check if it is android platform or not in the Start function. #if UNITY_ANDROID currentPlatformAndroid = true; #Else currentPlatformAndroid = false; #Endif

31 CODE Modification In the FixedUpdate() function and other event handlers, if (currentPlatformAndroid == true) { // Write code for Android Mobile } else // Write code for Desktop

32 CODE Modification Android specific coding public void Accelerometer()
{ float x = Input.acceleration.x; float y = Input.acceleration.y; if (x < -0.1f) MoveLeft(); else if (x > 0.1f) MoveRight(); else if (y < -0.1f) MoveUp(); else if (y > 0.1f) MoveDown(); else SetVelocityZero(); }

33 CODE Modification Code common to all platforms.
public void MoveLeft() { rb.velocity = new Vector3(-speed, 0,0); } public void MoveRight() { rb.velocity = new Vector3(speed, 0,0); public void MoveUp() { rb.velocity = new Vector3(0, 0, speed); public void MoveDown() { rb.velocity = new Vector3(0, 0, -speed); public void SetVelocityZero() { rb.velocity = Vector3.zero;

34 UNITY project BUILD Modification
IN UNITY, File  Build Setting Switch Platform from PC, MAC, Linux to Android File  Build Settings  PlayerSettings Specify Comopany Name, Product Name, builder Identifier

35

36 UNITY project BUILD Modification
Connect an Android phone to your computer using USB. File  Build & Run It will ask you to run on the connected Android phone or a virtual device. You can also build an .APK file to distribute to others (.APK files are executables for Android) File  Build  Build Once the build is done, it will ask for a location to save the APK file. Now you can the APK file to your friends and let them save it on their Android mobile device to run.

37

38 UNITY project BUILD Modification
If you are working on Windows, you may get an error message about incorrect sdk path. You then need to download tools_r windows.zip Unzip it. You Unzip it you will find a “tools” folder. Use it to replace the “tools” folder Android SDK directory.

39 References mobile-22125


Download ppt "Vijay Kumar Kolagani Dr. Yingcai Xiao"

Similar presentations


Ads by Google