Building Apps with Connectivity & the Cloud. Connecting Devices Wirelessly Performing Network Operations Transferring Data Without Draining the Battery.

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

1 Vendor ITB - Sourcing User Guide. 2 Minimum System Requirements Internet connection - Modem, ISDN, DSL, T1. Your connection speed determines your access.
 Copyright I/O International, 2013 Visit us at: A Feature Within from Vendor Payment Terms User Friendly Maintenance 
Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
USING ANDROID WITH THE INTERNET. Slide 2 Network Prerequisites The following must be included so as to allow the device to connect to the network The.
Introduction to push technology © 2009 Research In Motion Limited.
1 Chapter 12 Working With Access 2000 on the Internet.
Automating Tasks With Macros
Wireless LAN Topology Visualiser Project Supervisor: Dr Arkady Zaslavsky Project Team Members: Jignesh Rambhia Robert Mark Bram Tejas Magia.
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
CS378 - Mobile Computing Connecting Devices. How to pass data between devices? – Chat – Games – Driving Options: – Use the cloud and a service such as.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
Aurora: A Conceptual Model for Web-content Adaptation to Support the Universal Accessibility of Web-based Services Anita W. Huang, Neel Sundaresan Presented.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
CS378 - Mobile Computing Web - WebView and Web Services.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Server-side Scripting Powering the webs favourite services.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Moodle (Course Management Systems). Assignments 1 Assignments are a refreshingly simple method for collecting student work. They are a simple and flexible.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Mobile Application Development using Android Lecture 2.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
CS378 - Mobile Computing Web - WebView and Web Services.
1. Insert the Resource CD into your CD-ROM drive, click Start and choose Run. In the field that appears, enter F:\XXX\Setup.exe (if “F” is the letter of.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Procrastinator: Pacing Mobile Apps’ Usage of the Network mobisys 2014.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Getting Started with OPC.NET OPC.NET Software Client Interface Client Base Server Base OPC Wrapper OPC COM Server Server Interface WCF Alternate.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Android networking 1. Network programming with Android If your Android is connected to a WIFI, you can connect to servers using the usual Java API, like.
Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,
Evaluating & Maintaining a Site Domain 6. Conduct Technical Tests Dreamweaver provides many tools to assist in finalizing and testing your website for.
FCM Workflow using GCM.
Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Users are moving towards web applications Content on the web is more personal & meaningful Development on the web is easier than the OS.
Adding network connections. Connecting to the Network To perform the network operations, your application manifest must include the following permissions:
CITA 310 Section 4 Apache Configuration (Selected Topics from Textbook Chapter 6)
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Exploring Mobile Device Networking Lesson 4. Exam Objective Matrix Skills/ConceptsMTA Exam Objectives Understanding Networking for Mobile Devices Network.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Presenter: Tyler Newsome
Project Management: Messages
Instructor: Mazhar Hussain
Section 13 - Integrating with Third Party Tools
MAD.
Activities and Intents
Web Caching? Web Caching:.
Configuring Internet-related services
CS371m - Mobile Computing Responsiveness.
CS323 Android Topics Network Basics for an Android App
Presentation transcript:

Building Apps with Connectivity & the Cloud

Connecting Devices Wirelessly Performing Network Operations Transferring Data Without Draining the Battery Syncing to the Cloud

Connecting Devices Wirelessly Network Service Discovery (NSD) Describes the key APIs for finding and connecting to other devices from your application. Using NSD Connecting with Wi-Fi Direct Using Wi-Fi Direct for Service Discovery

Using NSD Adding NSD to your app allows your users to identify other devices on the local network that support the services your app requests. 1.Setting up a discovery listener with the relevant callbacks 2.Making a single asynchronous API call to discoverServices().

First, instantiate an anonymous class that implements NsdManager.DiscoveryListener This snippet does several checks when a service is found. 1.The service name of the found service is compared to the service name of the local service to determine if the device just picked up its own broadcast (which is valid). 2. The service type is checked, to verify it's a type of service your application can connect to. 3. The service name is checked to verify connection to the correct application.

It must first determine the connection information for that service, using the resolveService() method. Implement a NsdManager.ResolveListener to pass into this method.

Connecting with Wi-Fi Direct Shows you how to find and connect to nearby devices using Wi-Fi Direct. Set Up Application Permissions

Set Up a Broadcast Receiver and Peer-to-Peer Manager WIFI_P2P_STATE_CHANGED_ACTION indicates whether Wi-Fi Peer-To-Peer (P2P) is enabled WIFI_P2P_PEERS_CHANGED_ACTION indicates that the available peer list has changed. WIFI_P2P_CONNECTION_CHANGED_ACTION indicates the state of Wi-Fi P2P connectivity has changed. WFIF_P2P_THIS_DEVICE_CHANGED_ACTION indicates this device's configuration details have changed. Create a new BroadcastReceiver class that you'll use to listen for changes to the System's Wi-Fi P2P state. In the onReveive() method, add a condition to handle each P2P state change listed above.

Initiate Peer Discovery discoverPeers() The WifiP2pManager.Channel you received back when you initialized the peer-to-peer mManager. An implementation of WifiP2pManager. ActionListener with methods the system invokes for successful and unsuccessful discovery.

Connect to a Peer In order to connect to a peer, create a new WifiP2pConfig object, and copy data into it from the WifiP2pDevice representing the device you want to connect to. Then call the connect() method.

Connecting to the Network Managing Network Usage Parsing XML Data Performing Network Operations

Note that to perform the network operations described in this lesson, your application manifest must include the following permissions: Connecting to the Network

Choose an HTTP Client HttpURLConnection and Apache HttpClient Using HttpURLConnection for applications targeted at Gingerbread and higher. 智能手機操作系統 Android 2.3 ,代號 Gingerbread ( 薑餅 )

Perform Network Operations on a Separate Thread To prevent this from causing a poor user experience, always perform network operations on a separate thread from the UI. AsyncTask dolnBackground() executes the method downloadUrl(). It passes the web page URL as a parameter. The method downloadUrl() fetches and processes the web page content. When it finishes, it passes back a result string. onPostExecute() takes the returned string and displays it in the UI.

When users click the button that invokes myClickHandler(), the app passes the specified URL to the AsyncTask subclass DownloadWebpageTask. The AsyncTask method doInBackground() calls the downloadUrl() method. The downloadUrl() method takes a URL string as a parameter and uses it to create a URL object. The URL object is used to establish an HttpURLConnection. Once the connection has been established, the HttpURLConnection object fetches the web page content as an InputStream. The InputStream is passed to the readIt() method, which converts the stream to a string. Finally, the AsyncTask's onPostExecute() method displays the string in the main activity's UI.

Connect and Download Data In your thread that performs your network transactions, you can use HttpURLConnection to perform a GET and download your data. After you call connect(), you can get an InputStream of the data by callinggetInputStream() the doInBackground() method calls the method downloadUrl(). ThedownloadUrl() method takes the given URL and uses it to connect to the network via HttpURLConnection. Once a connection has been established, the app uses the method getInputStream() to retrieve the data as anInputStream.

Convert the InputStream to a String An InputStream is a readable source of bytes. Once you get an InputStream, it's common to decode or convert it into a target data type

Managing Network Usage Describes how to write applications that have fine-grained control over their usage of network resources. If your application performs a lot of network operations, you should provide user settings that allow users to control your app's data habits

Check a Device's Network Connection A device can have various types of network connections. Wi_Fi and Mobile network A common strategy for apps is to only fetch large data if a Wi-Fi network is available.

To check the network connection, you typically use the following classes: 1. ConnectivityManager : Answers queries about the state of network connectivity. It also notifies applications when network connectivity changes. 2. NetworkInfo : Describes the status of a network interface of a given type (currently either Mobile or Wi-Fi).

You should not base decisions on whether a network is "available." You should always check isConnected() before performing network operations A more concise way of checking whether a network interface is available is as follows. The method getActiveNetworkInfo() returns a NetworkInfo instance representing the first connected network interface it can find, or null if none of the interfaces is connected (meaning that an internet connection is not available)

You can implement a preferences activity that gives users explicit control over your app's usage of network resources. Your manifest must have the right permissions and intent filters. You can declare the intent filter for the ACTION_MANAGE_NETWORK_USAGE acti on (introduced in Android 4.0) to indicate that your application defines an activity that offers options to control data usage.

Respond to Preference Changes When the user changes preferences in the settings screen, it typically has consequences for the app's behavior. if there is a match between the setting and the device's network connection, the app downloads the feed and refreshes the display.

Detect Connection Changes When the device's network connection changes, NetworkReceiver intercepts the action CONNECTIVITY_ACTION, determines what the network connection status is, and sets the flags wifiConnected and mobileConnected to true/false accordingly. Setting up a BroadcastReceiver that gets called unnecessarily can be a drain on system resources.

Parsing XML Data Extensible Markup Language (XML) is a set of rules for encoding documents in machine- readable form. Choose a Parser We recommend XmlPullParser, which is an efficient and maintainable way to parse XML on Android.

Analyze the Feed The first step in parsing a feed is to decide which fields you're interested in. The parser extracts data for those fields and ignores the rest.

Instantiate the Parser Instantiate a parser and kick off the parsing process. A parser is initialized to not process namespaces, and to use the provided InputStream as its input.

Read the Feed The readFeed() method does the actual work of processing the feed. It looks for elements tagged "entry" as a starting point for recursively processing the feed. If a tag isn't an entry tag, it skips it. Once the whole feed has been recursively processed, readFeed() returns a List containing the entries (including nested data members) it extracted from the feed. This List is then returned by the parser.

Parse XML As described in Analyze the Feed, identify the tags you want to include in your app. This example extracts data for the entry tag and its nested tags title, link, and summary. Create the following methods: A "read" method for each tag you're interested in. Methods to extract data for each different type of tag and to advance the parser to the next tag

Transferring Data Without Draining the Battery Optimizing Downloads for Efficient Network Access Minimizing the Effect of Regular Updates Redundant Downloads are Redundant Modifying your Download Patterns Based on the Connectivity Type

Optimizing Downloads for Efficient Network Access The Radio State Machine The state machine for a typical 3G network radio consists of three energy states: Full power: Used when a connection is active, allowing the device to transfer data at its highest possible rate. Low power: An intermediate state that uses around 50% of the battery power at the full state. Standby: The minimal energy state during which no network connection is active or required.

The general principles and resulting best practices are applicable for all wireless radio implementations Vary based on the wireless radio technology employed (2G, 3G, LTE, etc.) This approach is particularly effective for typical web browsing as it prevents unwelcome latency while users browse the web.

How Apps Impact the Radio State Machine In the case of the typical 3G radio state machine described above, it will remain at full power for the duration of your transfer—plus an additional 5 seconds of tail time—followed by 12 seconds at the low energy state. So for a typical 3G device, every data transfer session will cause the radio to draw energy for almost 20 seconds.

In practice, this means an app that transfers unbundled data for 1 second every 18 seconds will keep the wireless radio perpetually active, moving it back to high power just as it was about to become idle. As a result, every minute it will consume battery at the high power state for 18 seconds, and at the low power state for the remaining 42 seconds Unbundled Transfer

By comparison, the same app that bundles transfers of 3 seconds of every minute will keep the radio in the high power state for only 8 seconds, and will keep it in the low power state for only an additional 12 seconds Bundled Transfer

Syncing to the Cloud Using the Backup API Making the Most of Google Cloud Messaging

Using the Backup API When a user purchases a new device or resets their existing one, they might expect that when Google Play restores your app back to their device during the initial setup, the previous data associated with the app restores as well. By default, that doesn't happen and all the user's accomplishments or settings in your app are lost.

Register for the Android Backup Service Write Your Backup Agent Request a Backup Restore from a Backup

END