Android Intents & Sensors CSE651C, B.Ramamurthy 4/8/2019
References https://developer.android.com/reference/android/content/Intent.html CSE651C, B.Ramamurthy 4/8/2019
Intents What are intents? “An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.” Example it bridges the need for communication between apps: Android App1 Android App1 Intent CSE651C, B.Ramamurthy 4/8/2019
Email is a common intent See the code below for email intent: Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email"); intent.putExtra(Intent.EXTRA_TEXT, "Body of email"); intent.setData(Uri.parse("mailto:default@recipient.com")); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); CSE651C, B.Ramamurthy 4/8/2019
Use Cases “An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use cases:” Starting an Activity..like a timer within an app Starting an underlying Service.. Scheduler service Delivering a broadcast: push a message to a group. CSE651C, B.Ramamurthy 4/8/2019
Lets look at an example Simple App, that writes the text view to logs, but it can also send to an email specified. CSE651C, B.Ramamurthy 4/8/2019
Sensors Android supports a broad category of sensors: Motion sensors: accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. Environmental sensors: for air temperature and pressure, illumination, and humidity Position sensors: orientation sensors and magnetometers. CSE651C, B.Ramamurthy 4/8/2019
Sensor Framework Sensor manager Sensor Sensor event 4/8/2019 CSE651C, B.Ramamurthy 4/8/2019
Example code: Accelerometer Lets explore the code and activity for an accelerometer sensor The code is available in ublearns. Download it and open it Lets review the code and execute the example If you upload it to your Android phone you can actually see it working. CSE651C, B.Ramamurthy 4/8/2019
Summary We looked at Android Intent and Android Sensors framework. These are very powerful features of Android that make it a comprehensive tool/device than just a phone Get deeper into these two topics for developing apps and also for adding other Intents and sensors. Automotive domain is a fertile area for exploration in Intents and sensors. CSE651C, B.Ramamurthy 4/8/2019