IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

Similar documents
Services. Marco Ronchetti Università degli Studi di Trento

Android Services. Victor Matos Cleveland State University. Services

Services. Marco Ronchetti Università degli Studi di Trento

EMBEDDED SYSTEMS PROGRAMMING Android Services

Software Practice 3 Before we start Today s lecture Today s Task Team organization

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Broadcast receivers. Marco Ronchetti Università degli Studi di Trento

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Embedded Systems Programming - PA8001

Notification mechanism

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

MOBILE APPLICATION DEVELOPMENT LECTURE 10 SERVICES IMRAN IHSAN ASSISTANT PROFESSOR

Android Service. Lecture 19

Android. Broadcasts Services Notifications

Table of Content Android Tutorial... 2 Audience... 2 Prerequisites... 2 Copyright & Disclaimer Notice... 2 Overview... 7

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Tabel mysql. Kode di PHP. Config.php. Service.php

<uses-permission android:name="android.permission.internet"/>

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Android HelloWorld - Example. Tushar B. Kute,

LifeStreet Media Android Publisher SDK Integration Guide

App Development for Smart Devices. Lec #4: Services and Broadcast Receivers

Vienos veiklos būsena. Theory

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

Services. Background operating component without a visual interface Running in the background indefinitely

Manifest.xml. Activity.java

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Basic GUI elements - exercises

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Created By: Keith Acosta Instructor: Wei Zhong Courses: Senior Seminar Cryptography

Active Monitoring System for Android Devices using Cloud 1 Sagar Bhalodia, 2 K. Navin 1 Student, 2 Assistant Professor

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Mobile Development Lecture 9: Android & RESTFUL Services

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Android Application Development. By : Shibaji Debnath

Android Workshop: Model View Controller ( MVC):

Learn about Android Content Providers and SQLite

Introduction to Android Development

INTRODUCTION TO ANDROID

A Crash Course to Android Mobile Platform

Android Beginners Workshop

Intents. Your first app assignment

Android UI Development

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

Solving an Android Threading Problem

An Overview of the Android Programming

Understanding Intents and Intent Filters

Software Practice 3 Today s lecture Today s Task

Getting Started With Android Feature Flags

Fragment Example Create the following files and test the application on emulator or device.

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Mobile Software Development for Android - I397

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Interface ใน View class ประกอบด วย

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Android - JSON Parser Tutorial

Simple Currency Converter

App Development for Android. Prabhaker Matet

Android Tutorial: Part 3

Mobila applikationer och trådlösa nät, HI1033, HT2012

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

COMP61242: Task /04/18

ANDROID PROGRAMS DAY 3

Starting Another Activity Preferences

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

By The Name of Allah. The Islamic University of Gaza Faculty of Engineering Computer Department Final Exam. Mobile Computing

Android + TIBBO + Socket 建國科技大學資管系 饒瑞佶

Agenda. The Android GUI Framework Introduction Anatomy A real word example Life cycle Findings

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices.

Multiple Activities. Many apps have multiple activities

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Create Parent Activity and pass its information to Child Activity using Intents.

else if(rb2.ischecked()) {

Meniu. Create a project:

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Fragments. Lecture 11

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Notifications and Services. Landon Cox March 28, 2017

Android - Widgets Tutorial

Mobila applikationer och trådlösa nät, HI1033, HT2013

Our First Android Application

Android Programs Day 5

Text Properties Data Validation Styles/Themes Material Design

LAMPIRAN. byte bcdtodec(byte val) { return( (val/16*10) + (val%16) ); } void setup() {

Android for Java Developers Dr. Markus Schmall, Jochen Hiller

Import the code in the top level sdl_android folder as a module in Android Studio:

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Embedded Systems Programming - PA8001

Upcoming Assignments Quiz Friday? Lab 5 due today Alpha Version due Friday, February 26

CS 4330/5390: Mobile Application Development Exam 1

Transcription:

Learning Unit Exam Project IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application. The delivery of this project is essential therefore a requirement for submission of the special examination of this learning unit. Please, read text very carefully before start to answer it. SECTION I. 1. Develop the following steps to construct an Android application to use a Web service within Android. 2. Create an Android application HelloWorld for using the Web service. 3. Write the code for the main activity file MainActivity.java and include the startservice() and stopservice() methods. 4. Create the java file MyService.java containing an implementation of Android service related methods. 5. In the AndroidManifest.xml file use <service.../> tag and define the service or services. 6. Insert a LinearLayout and two Buttons in the main.xml. 7. Insert two string tags start_service and stop_service in the strings.xml file. 8. Execute and verify the results in the application and note any changes. Suggested steps a. Include two startservice() and stopservice() methods to start and stop the service. public class MainActivity extends Activity { public void oncreate(bundle b) { super.oncreate(b); setcontentview(r.layout.activity_main); public void startservice(view view) { startservice(new Intent(getBaseContext(), MyService.class)); public void stopservice(view view) { stopservice(new Intent(getBaseContext(), MyService.class)); b. Next, the MyService.java file implementing the onstartcommand() and ondestroy() methods associated with Service. public class MyService extends Service { public IBinder onbind(intent arg0) { return null; public int onstartcommand(intent intent, int flags, int startid) { Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show(); return START_STICKY; public void ondestroy() { super.ondestroy(); Toast.makeText(this,"Service Destroyed",Toast.LENGTH_LONG).show(); Página 1

c. Modify the Manifest.xml file by adding a <service.../> tag. <manifest xmlnsandroid="http//schemas.android.com/apk/res/android" <application androidicon="@drawable/ic_launcher" androidlabel="@string/app_name" androidtheme="@style/apptheme" > <activity androidname=".mainactivity" androidlabel="@string/title_activity_main" > <intent-filter> <action androidname="android.intent.action.main" /> <category androidname="android.intent.category.launcher"/> </intent-filter> </activity> <service androidname=".myservice" /> </application> </manifest> d. Next, include two buttons in the main.xml file <LinearLayout xmlnsandroid="http//schemas.android.com/apk/res/android" <Button androidid="@+id/bstart" androidtext="@string/startservice" androidonclick="startservice" /> <Button androidid="@+id/bstop" androidtext="@string/stopservice" androidonclick="stopservice" /> </LinearLayout> e. Define constants in the strings.xml <resources> <string name="start_service">start Service</string> <string name="stop_service">stop Service</string> </resources> SECTION II. Construct a simple application to show how a web service is invoked using SOAP protocol in an Android application. The application will convert Celsius to Fahrenheit degrees. Use SOAP protocol to send and retrieve information in order to invoke web methods. The application will require an Internet connection to hit a Web Service hosted in a remote server and to check this is done before trying to hit Web Service. When a web method is invoked the application gets back the data within a XML file from the server. The response being received can be parsed and rendered in the current application if needed. 1. The layout configuration. Use an Android project with project name WebserviceActivity and insert the package name. Página 2

2. The XML layout. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlnsandroid="http//schemas.android.com/apk/res/android" androidlayout_width="match_parent" androidlayout_height="wrap_content" androidorientation="vertical" > <TextView androidid="@+id/textview1" androidlayout_width="fill_parent" androidlayout_height="wrap_content" androidtext="celsius to Farenheit" /> <EditText androidid="@+id/edittext1" androidlayout_width="fill_parent" androidlayout_height="wrap_content" androidnumeric="integer" /> <Button androidid="@+id/button1" androidlayout_width="fill_parent" androidlayout_height="wrap_content" androidtext="convert to Farenheit" /> <TextView androidid="@+id/tv_result" androidlayout_width="fill_parent" androidlayout_height="wrap_content" androidtext="" androidtextsize="24dp" /> </LinearLayout> 3. Download the KSOAP library and add to the lib folder of your Android project. 4. Create the needed objects for the WebserviceActivity class. An example is final String NAMESPACE = "http//www.w3schools.com/webservices/"; final String URL="http//www.w3schools.com/webservices/tempconvert.asmx"; final String SOAP_ACTION = "http//www.w3schools.com/webservices/celsiustofahrenheit"; final String METHOD_NAME = "CelsiusToFahrenheit"; String TAG = "PGGURU"; static String celsius, fahren; Button b; TextView tv; EditText et; oncreate() 5. Add enough code in the oncreate() method, as indicated. public void oncreate(bundle b) { super.oncreate(b); setcontentview(r.layout.main); et = (EditText) findviewbyid(r.id.edittext1); tv = (TextView) findviewbyid(r.id.tv_result); b = (Button) findviewbyid(r.id.button1); b.setonclicklistener(new OnClickListener() { public void onclick(view v) { if(et.gettext().length()!=0 && et.gettext().tostring()!=""){ celsius = et.gettext().tostring(); AsyncCallWS task = new AsyncCallWS(); Página 3

); task.execute(); else { tv.settext("enter Celsius degrees"); 6. The AsyncCallWS class. This class will execute the web service and its separate thread that calls the following methods onpreexecute(), doinbackground(), onprogressupdate(), and onpostexecute(). private class AsyncCallWS extends AsyncTask<String, Void, Void> { protected Void doinbackground(string params) { Log.i(TAG, "doinbackground"); getfahrenheit(celsius); return null; protected void onpostexecute(void result) { Log.i(TAG, "onpostexecute"); tv.settext(fahren + " F"); protected void onpreexecute() { Log.i(TAG, "onpreexecute"); tv.settext("calculating..."); protected void onprogressupdate(void values) { Log.i(TAG, "onprogressupdate"); 7. Create the method getfahrenheit() inside the WebserviceActivity class to invoke the web service. public void getfahrenheit(string celsius) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo celsiuspi = new PropertyInfo(); celsiuspi.setname("celsius"); celsiuspi.setvalue(celsius); celsiuspi.settype(double.class); request.addproperty(celsiuspi); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotnet = true; envelope.setoutputsoapobject(request); HttpTransportSE androidhttptransport = new HttpTransportSE(URL); try { androidhttptransport.call(soap_action, envelope); SoapPrimitive response = (SoapPrimitive) envelope.getresponse(); fahren = response.tostring(); catch (Exception e) { e.printstacktrace(); 8. The Internet permission into Manifest.xml. <uses-permission androidname="android.permission.internet" /> Página 4

9. Executing the service application should be similar to the following image Annotations. a. Report a detailed text and images for the whole application. b. Include in a Word file Personal data, Introduction, Development, Conclusions and Bibliography. c. Zip the project files into a folder and your name as indicated NameProject.zip. Página 5