You are on page 1of 44

Using Internet

Resources

1
Relay Sessions

• RL6.1 - Typical Architecture of Internet


Resources and their usage
• RL6.2 - Use of internet resources in various
application domains

2
Agenda

 Connecting to Internet Resources


 Use of Cloud
 Download Manager
 Files and Parsers
 Using Frameworks in Other Applications
Domains

3
Connecting to
Internet Resources

3
What is the need for creating internet
application?
• There are several benefit of creating thin client
application
• Bandwidth
• Caching
• Native Features
• Modern mobile offers the following techniques for
internet connectivity
• GPRS
• EDGE
• 3G

5
Connecting And Downloading Internet
Android offers several ways to access Internet resources.

• At one extreme you can use a WebView to include a WebKit-


based browser within an Activity.
• At the other extreme you can use client-side APIs, such as the
Google APIs, to interact directly with server processes.
• Somewhere in between, you can process remote XML feeds(
Custom API’s) to extract and process data using a Java-based
XML parser, such as SAX or the XML Pull Parser.

6
Connecting to Internet
• Android let your apps to connect to internet or any other
local network and allows you to perform network operation
• The following classes used checking network connection

• ConnectifyManager , getSystemService()
• URL, HttpURLConnection

7
Connecting to an Internet Resource

• Before you can access Internet resources, you need to add an


INTERNET uses-permission node to your application manifest,
as shown in the following XML snippet:

<uses-permission android:name=”android.permission.INTERNET”/>

8
Basic pattern for opening an Internet data
stream.
String myFeed = getString(R.string.my_feed);
try
{
URL url = new URL(myFeed);
// Create a new HTTP URL connection
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection =
(HttpURLConnection)connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
processStream(in);
}
}
catch (MalformedURLException e) {
Log.d(TAG, “Malformed URL Exception.”);
}
catch (IOException e) {
Log.d(TAG, “IO Exception.”);
}
9
Using Cloud

3
Cloud Web Services
• The following list shows some of the more matured and
interesting Internet services currently available.

 Google Services API’s


 Yahoo Pipes
 Google App Engine
 Amazon Web Services

11
Google API’s
In addition to the native Google applications, Google offers web APIs for
accessing to their

 Calendar
 Docs
 Blogger
 Picasa Web Albums platforms.

These APIs collectively make use of a form of XML for data communication.

Example

• With the Google Maps Android API, you can add maps to your app that
are based on Google Maps data.
• The Google Maps Android APIs are not included in the Android platform,
but are available on any device with the Google Play Store running
Android 2.2 or higher, through Google Play Services 12
Google API Engine
• Using the Google App Engine, you can create cloud-hosted
web services that shift complex processing away from your
mobile client.
• Doing so reduces the load on your system resources but
comes at the price of Internet-connection dependency.

13
Yahoo Pipes
• Yahoo! Pipes offers a graphical web-based approach to XML
feed manipulation.

• Using pipes, one can


• Filter
• Aggregate
• Analyze
• Manipulate XML feeds and output

• In a variety of formats to be consumed by your applications.

14
Amazon Web Services
• Amazon offers a range of cloud-based services, including a
rich API for accessing its media database of books, CDs, and
DVDs.
• Amazon also offers a distributed storage solution (S3- Best
Ex:Dropbox) and Elastic Compute Cloud (EC2-Virtual Servers).
• Amazon distinguishes its vendors because of the following

Flexible
Cost effective
Scalable and elastic
Secure 15
Usage of Cloud in Apps

• Cloud computing has taken IT world by storm


• Can write applications to take advantage of the
cloud and can leverage the faster time to market,
the agility, cost benefits, etc.
• Android in Traditional Environment

16
Usage of Cloud in Apps

• Android in Cloud Environement

17
Usage of Cloud in Apps

The cloud in the mobile world


● The cloud offers an invisible infrastructure capable to deliver
some services (SaaS)

● Some services you are using on a smartphone, are based on a


cloud service (ex: email, storaging, etc...)

● If the cloud handle user data, all his information can be


accessed everywhere and every time

● Documents, emails, images and many other data types, can be


accessed even if mobile devices get broken or get lost
Android and Google Cloud

● Google Drive, also, offers an online data storaging


and documents creation;
● Device configuration and application backup can be
pushed on Google Cloud
● It integrates your mobile devices with Google Maps
service enabling an online navigation system
● With Google App Engine, you can build powerful
application using Java, JVMcompatibles
(Groovy, Scala) or Python languages;

19
Download Manager

3
Using The Download Manager
• The Download Manager was introduced in Android 2.3 (API level
9) as a Service to optimize the handling of long-running
downloads.
• The Download Manager handles the HTTP connection and
monitors connectivity changes and system reboots to ensure
each download completes successfully.
• To Access the Download Manager:
• Request the DOWNLOAD_SERVICE using the getSystemService
method, as follows:
String serviceString = Context.DOWNLOAD_SERVICE;
DownloadManager downloadManager;
downloadManager =
(DownloadManager)getSystemService(serviceString); 21
Cancelling and Querying Downloads
• The Download Manager has the following methods
• Remove: method lets you cancel a pending download,
• Abort: a download in progress, or
• Delete : a completed download.

• You can query the Download Manager to find the


• Status
• Progress
• Details of your download requests
• by using the query method that returns a Cursor of
downloads.
• (As we know Cursors are a data construct used by Android to
return data stored in a Content Provider or SQLite database.)
22
Using Web Services
• Software as a service (SaaS) and cloud computing are
becoming increasingly popular as companies are trying to
reduce the cost overheads associated with installing,
upgrading, and maintaining deployed software.

• The result is a range of rich Internet services with which you


can build thin mobile applications that enrich online services
with the personalization available from your smartphone or
tablet.

23
Files and Parsers

3
Files in Android

• Android provides many kinds of storage for


applications storage to store their data
• Storage places are shared preferences,
o internal storage
o external storage
o SQLite storage
o storage via network.

25
Files

• The file comes in Internal storage, of the private data


• These files are private and are accessed by only your
application and get deleted, when user delete
application
• Files are handled by using
• FileInputStream
• FileOutputStream

26
Local File System

• Flat File Storage

• Not recommended to use Files


• If used, the it is used to store large amount of
data
• Use I/O interfaces provided by java.io.* libraries
to read/ write files
• Only local files can be accessed
Advantage : large amount of data can be stored
Disadvantage : Updating file involves lot of coding

27
Saving and Loading of Files

• Android offeres openFileInput and openFileOutput


to simplify reading and writing streams from and to
local files

• Support only those files in the current application


folder; specifying path separators will cause an
exception to be thrown

• Files created using the openFileOutput method are


private to the calling application

28
File Operations
• File Operation (Read)
 Read file
• Use Context.openFileInput(String name) to open private
input file related to program
Throw FileNotFoundException when file does not exists
• You Can find the location of the file stored in your
Sandbox by calling getFilesDir
• File Operation (Write)
Write File
• Use Context.openFileOutput(String name, int mode) to
open private file
• File will be created if it does not exists
• Output stream can be opened in append mode which
means new data will be appended to end of file 29
File Operations (Contd.,)

30
Including Static File as a Resource

• Static files that are created in application are created


in /res/raw directory
• Read only static files
• Use Resources.openRawResource(R.raw.mydatafile)
to open static files

31
File Management Tools

• Android supply some Specialized utilities for file


management that are available from the
application Context

deleteFile(Enables you to remove files Created by


the current applciation)
fileList(returns a string array that includes all the
files created by the current application)

• Useful for cleaning up temporary files left behind if


your application crashes or is killed unexpectedly
32
External Storage
• Android compatible device supports external storage that can be
used to save files
Removable storage media (SD card)

• World readable files


• User can modify it
• Private to application
• Get removed when application is uninstalled
• getExternalFiles method supports parameter values like
DIRECTORY_MUSIC or DIRECTORY_RINGTONES

• For public shared directories use


getExternalStoragePublicDirectory()
33
External Storage
• For cache files use getExternalCacheDirectory()

• Available in API level 8 and above

• For API level 7 and below use :


getExternalStorageDirectory()
Private files are stored in /Android/data/<package_name>/files
Cache files are stored in /Android/data/<package_name>/cache

34
Parser

• Android allows parsing of XML


• It is used for processing remote XML feeds
• Java based XML parser
• SAX , javax
• Android based XML parser
• XmlPullParser

35
Parsing XML Using Pull Parser

• The XML Pull Parser API is available from the


following libraries:
• import org.xmlpull.v1.XmlPullParser;
• Import rg.xmlpull.v1.XmlPullParserException;
• import org.xmlpull.v1.XmlPullParserFactory;

It enables you to parse an XML document in a


single pass.
Pull Parser presents the elements of your
document in a sequential series of events and
tags.
36
Using Framework in
Other Application
Domain

3
Top 10 Android ready Development
Frameworks (Contd.,)
• The following are Top 10 of the most popular Android
development tools. Unless otherwise noted, they are
open source, cross-platform frameworks:

1. Basic4android: Anywhere Software's commercial RAD


tool and IDE for Android provides a comprehensive
feature set and an object-oriented programming
language similar to Visual Basic.

http://www.basic4ppc.com/android/why.html

38
Top 10 Android ready Development
Frameworks (Contd.,)
2. Corona SDK: Widely used among game developers, Corona is
also a popular, general-purpose framework. Corona Labs
(formerly Ansca Mobile) claims an installed base of 120,000
developers. This high-end, commercial SDK offers over 500
APIs, as well as advertising and native UI support, and a built-in
physics engine.
2. http://www.coronalabs.com/

3. DHTMLX Touch: This JavaScript and AJAX library focuses on UI


widgets, and is aimed at building HTML5-based apps.
http://www.dhtmlx.com/touch/

39
Top 10 Android ready Development
Frameworks (Contd.,)
4. Dojo Mobile: The Dojo community's BSD-licensed
HTML5/JavaScript framework has added MVC and app-controller
packages, as well as mobile-specific components such as switches
and sliders. A degree of PhoneGap compatibility is also available.
4. http://dojotoolkit.org/features/mobile

5. iUI: This lightweight web UI framework includes a JavaScript


library, CSS support, and development images.
http://www.iui-js.org/

40
Top 10 Android ready Development
Frameworks (Contd.,)
6. jQuery Mobile: This popular, lightweight HTML5-based
framework is built on jQuery, and focuses on semantic markup,
progressive enhancement, and themable design. It's the leading
cross-platform framework among Eclipse open source developers.
http://jquerymobile.com/

7. Kendo UI: Telerik's HTML5/JavaScript framework is available in


open source and commercial versions. Kendo UI offers a wide
selection of UI widgets and plugins, and provides an MVVM
framework, performance optimization, and validation and
internationalization features.
http://www.kendoui.com/

41
Top 10 Android ready Development
Frameworks (Contd.,)
8. Mono for Android: Xamarin's C#- and enterprise-oriented
package is compatible with a similar iOS-based MonoTouch
version, and can also share code with the C#-based Windows
Phone. Mono supplies an environment conducive to Visual
Basic developers, and is touted for its debugger and native
binary compiler.
http://xamarin.com/

9. MoSync SDK: MoSync supports C++, HTML5/JavaScript, or both


on up to nine different platforms. The SDK is touted as being
compatible with PhoneGap, as well MoSync's own new
HTML5/JavaScript-based native mobile app
developer/simulator, MoSync Reload.
http://www.mosync.com/ 42
Top 10 Android ready Development
Frameworks (Contd.,)
10. PhoneGap: Designed for JavaScript, HTML5, and CSS
development, PhoneGap is now sponsored by Adobe and the
Apache Foundation. The 2.0 version adds Windows Phone
support, new CLI functions, and overhauled JavaScript libraries.
It also debuts Cordova WebView, an embeddable HTML
rendering control that uses Apache's Cordova-JS API for tasks
such as integrating PhoneGap code into larger native apps.
http://phonegap.com/

43
Thank-You
58

You might also like