SlideShare une entreprise Scribd logo
1  sur  62
Télécharger pour lire hors ligne
JavaME + Android in action
Java Platforms for Mobility
             CEJUG CCT
Coffee with Tapioca, December 2008
           Vando Batista

            Some Rights Reserved
Objectivity
Introduce the Java development platforms for
                 mobile devices,
        JavaME and Android, performing
  implementations activities for each one, in a
       lab-style practice, with some APIs

Target audience: Java developers interested on
               Mobile Platforms
Agenda
•   Overview on Mobile Platforms
•   Java ME in action
•   Android in action
•   Challenge
After this course you will…
• identify mobile platforms characteristics
• understand how to implement a JavaME
  application
• understand how to implement a Android
  application
• have implemented, at least, one application
  for each platform

• maybe… win a book: Free Software and Digital
  Inclusion (in Portuguese)
Applications…
•   Location Based Systems
•   m-commerce, collaboration, marketing
•   Mobile Social Networks
•   Military
•   Search and safety

On the move apps
                      Improve user experience
Users: mobile vs. desktop




• India: Many more mobile than desktop Web users (4 to 1),
  The Economic Times, Oct 2007
Motivation
• Evolution, popularization
  – Device resources
  – Connectivity
• Business applications for mobile devices
  – Growing 102% per year, until 2012 - Mobile
    Business Applications and Services, ABI Research
• New services, new opportunities
Mobile Ecosystem




Source: SDN - java.sun.com/javame
Mobile, Portable Devices
Mobile Networks


3G, 4G...
Development Platforms
Mobile Computing
  “Computing that deals with connection
      exploration on mobile devices”
Coulouris, Dellimore, Kindberg. Distributed Systems (4th edition)

         Mobility transparency
 allows the movement of resources and clients
      within a system without affecting the
  operation of users or programs. Two flavours:
            migration and relocation
quot;small is the betterquot;
• Challenges
  – Devices
  – Networks
  – Limitations and heterogeneity
• Dependencies
  – Power: battery autonomy
  – Resource: connection availability

“Remember that there is no code faster than no
     code” Taligent‘s Guide to Designing Programs
Mobile Development
• Software Development Kit (SDK)
  – Emulator, Documentation, Tools, Services, etc.
• Integrated Development Environment (IDE)
• IDE Plugins
Are you ready?


       Set your
     environments!
http://www.cejug.org/display/cejug/Ambiente+para+os+mini-
                cursos+de+JavaME+e+Android
Welcome to the…

  JavaME
Development
Introduction
• Java Platform, Micro Edition
    – Java Community Process (JCP) based
    – Java Specification Request (JSR)
       • Reference Implementation (RI)
       • Test Compatibility Kit (TCK)
•   Proprietary APIs
•   Native Applications
•   Since 2000
•   80% handsets: 1.2bi phones, 1200 models,
    180 carriers
Architecture




   • JVM, KVM
Source: SDN - java.sun.com/javame
Core APIs
• Configuration
  – CLDC, CDC, BD-J
• Profile
  – MIDP, IM, PP, PBP, FP
• Umbrella
  – Fragmentation: Computational, Physical,
    Functional
  – JTWI, MSA (Full, Subset)
Development Infrastructure
• Many environments: handset dependency
• For this lab:
  – SDK: Sun WTK 2.5.2, JME SDK 3.0
  – IDE: Eclipse Ganymede (3.4)
  – Plugin: Mobile Tools for Java 0.9
• Unified Emulator Interface (UEI)
Hello JavaME World!
• build, obfuscate, preverify, run, debug, and
  deploy
• Create a project
• Project structure
• Create a MIDlet
  – javax.microedition.midlet.MIDlet
• Over the Air (OTA) / installation
• On Device Deployment/Debug
• MIDlet.this.platformRequest(“tel:*”)
MIDlet Lifecycle
• Application Management Software (AMS)
  – Java Application Manager (JAM)




• notifyDestroyed()
• notifyPaused()
• resumeRequest()
MIDlet Lifecycle
              Coding
import javax.microedition.midlet.MIDlet;
public class HelloWorld extends MIDlet {
  public HelloWorld() {
    System.out.println(“MIDlet constructorquot;);
  }
  protected void destroyApp(boolean arg0) {
    System.out.println(quot; MIDlet destroyApp()quot;);
  }
  protected void pauseApp() {
    System.out.println(quot; MIDlet pauseApp()quot;);
  }
  protected void startApp() {
    System.out.println(quot; MIDlet startApp()quot;);
  }
}
Application Packaging
• Profile dependent
• MIDlet Suite
  – Java ARchive (.JAR)
  – Java Application Descriptor (.JAD)
• Package generation
Application Configuration
•   Java Application Descriptor (.JAD), Manifest
•   MIDlets
•   Permissions
•   Properties:
    – System
System.getProperty(“javax.microedition.*”)
    – Application
MIDlet.this.getAppProperty(quot;propertyNamequot;)
Code Optimization
•   Free objects
•   String Vs. StringBuffer
•   Arrays Vs. Collection
•   Moderate use
    –   Synchronized
    –   Instance variables
    –   Parameter number
    –   Resources initiation
    –   Interfaces, internal classes
• JAR obfuscation, compression
GUI




      Source: IBM - ibm.com
GUI
                     Coding
public class HelloWorld extends MIDlet {
  private Display display;
  private Form myForm;
// initialization on MIDlet constructor

    public startApp() {
      display = Display.getDisplay(this);
      // display.getCurrent();
      display.setCurrent(myForm);
    }
    ...

}
Keyboard Handling
• Components
  – javax.microedition.lcdui.CommandListener
  – javax.microedition.lcdui.Command
• Registration
  – setCommandListener(CommandListener l)
• Notification
  – commandAction(Command c, Displayable d) {}
• Potential deadlock: operations such as IO and
  networking should run on a separate thread
Keyboard Handling
            Coding
public class HelloWorld extends MIDlet {
  Displayable d = new TextBox(“Title”, “Body”,
  20,TextField.ANY);
  Command c = new Command(“Exit”, Command.EXIT, 0);
  d.addCommand(c);
  d.setCommandListener(new CommandListener() {
    public void commandAction(Command c, Displayable
  s) {
      doSomeAction();
    }
  } );
}
Persistent Storage
• Record Management System (RMS)
    – javax.microedition.rms.*
•   RecordStore
•   RecordEnumeration
•   RecordComparator
•   RecordFilter
Persistent Storage
            Coding
...
RecordStore rs = null;
String value = quot;Java ME in actionquot;;
...
try {
  rs = RecordStore.openRecordStore(“RecName”, true);
  byte[] recData = value.getBytes();
  rs.addRecord(recData, 0, recData.length);
  String data = new String(rs.getRecord(1));
} catch (Exception e) {
...
}
Connectivity
• Generic Connection Framework (GCF)
   – javax.microedition.io.*
• Remote (Infrastructured)
   –   HTTP, HTTPS
   –   TCP, UDP
   –   Wireless Messaging (JSR120, 205)
   –   Push Registry (MIDP)
   –   SIP (JSR180)
• Local (Ad hoc)
                                          Source: SDN - java.sun.com/javame
   – JABWT (JSR 82)
   – Ad Hoc Networking API (JSR 259)
Connectivity
                Coding
HttpConnection httpConn = null;
InputStream = null;
try {
  httpConn = (HttpConnection)
  Connector.open(quot;http://www.cejug.orgquot;);
  httpConn.setRequestMethod(HttpConnection.GET);
  httpConn.setRequestProperty(quot;User-Agentquot;,
  quot;Profile/MIDP-2.0 Configuration/CLDC 1.1quot;);
  is = httpConn.openInputStream();
  int ch = -1;
  while((ch = is.read()) != -1){
    ...
  }
…
References
• Mobile and Embedded Guide to JavaOne 2008
   – http://wiki.java.net/bin/view/Mobileandembedded/JavaO
     ne2008
• A Survey of Java ME Today
   – http://developers.sun.com/mobility/getstart/articles/surv
     ey/
• Java ME Device Table
   – http://developers.sun.com/mobility/device/
• JEDI course (DFJUG)
   – http://jedi.wv.com.br
Welcome to the…

  Android
Development
Open Handset Alliance
                          Manufactures




   Semiconductors                                   Carriers




                Content                  Software
Introduction
• Software stack
  – Operating System
     • Linux Kernel (v2.6)
  – Middleware
     • Services
  – Applications
                                  HTC Dream (G1)
     • Java
• Dalvik: custom virtual machine for embedded
• Since 2008
Characteristics
• Applications…
  – without borders
  – are created equal
  – can run in parallel
  – can easily embed the web


• Open source
  – http://source.android.com
• Apache 2.0 and GLP v2 license
Architecture
Basic Components
• Activity
  – UI component (Form like) typically corresponding
    to one screen
• Intent Receiver
  – Set and respond to an external event: notifications
    or status changes. Can wake up your app
• Services
  – Task without UI that runs in the background
• Content Provider
  – Allow applications to share data
Packages
android.util       android.telephony
android.os         android.hardware
android.graphics
android.text       android.net.wifi
android.database   android.location
android.content    android.media
android.view       android.opengl
android.widget
android.app
Development Infrastructure
• Recommended environment
• For this lab:
  – SDK: AndroidSDK 1.0
     • QEMU-based (system image)
  – IDE: Eclipse Ganymede (3.4)
  – Plugin: Android Development Tool 0.8, WST
• Add to environment variable PATH
  – tools directory
• A lot of XML for application, activity, intent,
  layout, view, variable
Hello Android World!
• Create a project
• Create an Activity
  – android.app.Activity
• Project structure
• LogCat
• Deployment/Debug
Application Configuration
• AndroidManifest.xml
• Application
   – Activity, Intent Filter
• Permissions
<?xml version=quot;1.0quot; encoding=quot;utf-8quot;?>
<manifest
xmlns:android=quot;http://schemas.android.com/apk/res/androidquot;
      package=quot;org.cejug.androidquot;
      android:versionCode=quot;1quot;
      android:versionName=quot;1.0.0quot;
      android:screenOrientation=quot;landscapequot;>
...
Application Anatomy
• Activity
   – Can reuse functionality from other components by
     making a request in the form of an Intent
   – Can be replaced at any time by a new Activity
     with an equivalent IntentFilter
• Intent
   – Request to do something: move from screen to
     screen. Activity.startActivity(myIntent)
• Intent Filter
   – Description of Intent types
Application Configuration

...
<application android:icon=quot;@drawable/iconquot;
        android:label=quot;@string/app_namequot;>
    <activity android:name=quot;.HelloActivityquot;
               android:label=quot;@string/app_namequot;>
         <intent-filter>
             <action android:name=quot;android.intent.action.MAINquot; />
             <category android:name=quot;android.intent.category.LAUNCHERquot; />
         </intent-filter>
    </activity>
    <activity android:name=quot;.HelloListActivityquot;
               android:label=quot;ListActivityquot;>
    </activity>
</application>
</manifest>
• Activities are
  stacked

• Only one is
  active

• Only one is
  open
Application
                  Coding
public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText(quot;Hello, Androidquot;);
        setContentView(tv);
        ...

    }
}
• onStart(), onResume(), onPause(), onStop(),
  onRestart(), onDestroy()
SDK Tools
•   Emulator
•   Dalvik Debug Monitoring System (ddms)
•   Android Debug Bridge (adb)
•   Android Asset Packaging Tool (aapt)
•   Android Interface Description Language (aidl)
•   sqlite3
•   Traceview
•   mksdcard
•   dx, activitycreator, and others
Application Packaging/Deployment
• APK file
  – .DEX
• Log into a Linux server via a shell
• Installation
  – adb install Application.apk
  – Uninstall
     • adb shell (remove file from /data/app/)
GUI
• Define in: code or XML
• res/layout
• Views
  – Text, Edit, List
  – Image, Web, Map
• Layouts
  – Frame, Linear, Relative, Table, Absolute
res/layout/main.xml - Views
<LinearLayout
xmlns:android=quot;http://schemas.android.com/apk/res/androidquot;
    android:orientation=quot;horizontalquot;
    android:layout_width=quot;fill_parentquot;
    android:layout_height=quot;wrap_contentquot;
    android:background=quot;@drawable/iconquot;>
res/layout/main.xml - Layouts
<Button android:id=quot;@+id/callButtonquot;
    android:layout_width=quot;fill_parentquot;
    android:layout_height=quot;wrap_contentquot;
    android:text=quot;Show Dialerquot; />

<EditText android:id=quot;@+id/phoneNumberquot;
    android:layout_width=quot;fill_parentquot;
    android:layout_height=quot;wrap_contentquot;
/>
Event Handling
                Coding
…
final EditText phoneNumber = (EditText)
       findViewById(R.id.phoneNumber);
Button callButton = (Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new Button.OnClickListener()
{
  public void onClick(View v) {
    Intent CallIntent = new Intent(Intent.ACTION_CALL, Uri
.parse(quot;tel:quot; + “+5585quot; + phoneNumber.getText()));
    CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(CallIntent);
}
});
Emulator: No support for…
•   Placing or receiving actual phone calls
•   USB connections
•   Camera/video capture (input)
•   Audio input
•   Determining connected state
•   Determining battery charge level / AC state
•   Bluetooth
References
• Android Documentation
  – http://code.google.com/android
• Android A Programmers Guide (Jerome
  DiMarzio, Mc Graw Hill)
• Professional Android Application Development
  (Reto Meier, Willey Publishing)
• Many sites, forums, videos, screencasts,
  presentations…
Would you like to be challenged?



  Practice matters!
Challenge Requirements
• Based on our lab practice
• Create an application on JavaME or Android
  platform following the requirement
  – Receive a user text input through a wizard
Questions & Answers
Thank you!
        Vando Batista
   vandofb at gmail.com
msn: vfbatista at hotmail.com
       skype: vfbatista

Contenu connexe

Tendances

Tendances (9)

Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
 
Android tutorial1
Android tutorial1Android tutorial1
Android tutorial1
 
Slides bootcamp21
Slides bootcamp21Slides bootcamp21
Slides bootcamp21
 
Apps development for Recon HUDs
Apps development for Recon HUDsApps development for Recon HUDs
Apps development for Recon HUDs
 
Android Overview
Android OverviewAndroid Overview
Android Overview
 
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM EuropeBlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
 
Android studio
Android studioAndroid studio
Android studio
 
Automated Historical Performance Analysis with kmemtracer
Automated Historical Performance Analysis with kmemtracerAutomated Historical Performance Analysis with kmemtracer
Automated Historical Performance Analysis with kmemtracer
 
Gl android platform
Gl android platformGl android platform
Gl android platform
 

En vedette (8)

Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
 
MIDP GUI Development: Alert, List, Form, TextBox
MIDP GUI Development: Alert, List, Form, TextBoxMIDP GUI Development: Alert, List, Form, TextBox
MIDP GUI Development: Alert, List, Form, TextBox
 
Introduction To J2ME(FT - Prasanjit Dey)
Introduction To J2ME(FT - Prasanjit Dey)Introduction To J2ME(FT - Prasanjit Dey)
Introduction To J2ME(FT - Prasanjit Dey)
 
Java ME CLDC MIDP
Java ME CLDC MIDPJava ME CLDC MIDP
Java ME CLDC MIDP
 
Session 3 J2ME Mobile Information Device Profile(MIDP) API
Session 3 J2ME Mobile Information Device Profile(MIDP)  APISession 3 J2ME Mobile Information Device Profile(MIDP)  API
Session 3 J2ME Mobile Information Device Profile(MIDP) API
 
It6611 mobile application development laboratory l t p c0 0 3 2
It6611 mobile application development laboratory l t p c0 0 3 2It6611 mobile application development laboratory l t p c0 0 3 2
It6611 mobile application development laboratory l t p c0 0 3 2
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Cs 6611 mad lab manual
Cs 6611 mad lab manualCs 6611 mad lab manual
Cs 6611 mad lab manual
 

Similaire à "JavaME + Android in action" CCT-CEJUG Dezembro 2008

A Taste of Java ME
A Taste of Java MEA Taste of Java ME
A Taste of Java ME
wiradikusuma
 
J2 Me Gaming Using Netbeans
J2 Me Gaming Using NetbeansJ2 Me Gaming Using Netbeans
J2 Me Gaming Using Netbeans
strongdevil
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
 

Similaire à "JavaME + Android in action" CCT-CEJUG Dezembro 2008 (20)

Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009
 
TK2323 Lecture 1 - Introduction to Mobile Application.pdf
TK2323 Lecture 1 - Introduction to Mobile Application.pdfTK2323 Lecture 1 - Introduction to Mobile Application.pdf
TK2323 Lecture 1 - Introduction to Mobile Application.pdf
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
A Taste of Java ME
A Taste of Java MEA Taste of Java ME
A Taste of Java ME
 
Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012
 
Introduction to Android - Mobile Portland
Introduction to Android - Mobile PortlandIntroduction to Android - Mobile Portland
Introduction to Android - Mobile Portland
 
Mobile Java
Mobile JavaMobile Java
Mobile Java
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009
 
Android application developement
Android application developementAndroid application developement
Android application developement
 
Cross Platform Mobile App Development
Cross Platform Mobile App DevelopmentCross Platform Mobile App Development
Cross Platform Mobile App Development
 
Session1 j2me introduction
Session1  j2me introductionSession1  j2me introduction
Session1 j2me introduction
 
Java vs .Net
Java vs .NetJava vs .Net
Java vs .Net
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 
Eclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for MicrocontrollersEclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for Microcontrollers
 
Developing a Modern Mobile App Strategy
Developing a Modern Mobile App StrategyDeveloping a Modern Mobile App Strategy
Developing a Modern Mobile App Strategy
 
J2 Me Gaming Using Netbeans
J2 Me Gaming Using NetbeansJ2 Me Gaming Using Netbeans
J2 Me Gaming Using Netbeans
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

"JavaME + Android in action" CCT-CEJUG Dezembro 2008

  • 1. JavaME + Android in action Java Platforms for Mobility CEJUG CCT Coffee with Tapioca, December 2008 Vando Batista Some Rights Reserved
  • 2. Objectivity Introduce the Java development platforms for mobile devices, JavaME and Android, performing implementations activities for each one, in a lab-style practice, with some APIs Target audience: Java developers interested on Mobile Platforms
  • 3. Agenda • Overview on Mobile Platforms • Java ME in action • Android in action • Challenge
  • 4. After this course you will… • identify mobile platforms characteristics • understand how to implement a JavaME application • understand how to implement a Android application • have implemented, at least, one application for each platform • maybe… win a book: Free Software and Digital Inclusion (in Portuguese)
  • 5. Applications… • Location Based Systems • m-commerce, collaboration, marketing • Mobile Social Networks • Military • Search and safety On the move apps Improve user experience
  • 6. Users: mobile vs. desktop • India: Many more mobile than desktop Web users (4 to 1), The Economic Times, Oct 2007
  • 7. Motivation • Evolution, popularization – Device resources – Connectivity • Business applications for mobile devices – Growing 102% per year, until 2012 - Mobile Business Applications and Services, ABI Research • New services, new opportunities
  • 8. Mobile Ecosystem Source: SDN - java.sun.com/javame
  • 12. Mobile Computing “Computing that deals with connection exploration on mobile devices” Coulouris, Dellimore, Kindberg. Distributed Systems (4th edition) Mobility transparency allows the movement of resources and clients within a system without affecting the operation of users or programs. Two flavours: migration and relocation
  • 13. quot;small is the betterquot; • Challenges – Devices – Networks – Limitations and heterogeneity • Dependencies – Power: battery autonomy – Resource: connection availability “Remember that there is no code faster than no code” Taligent‘s Guide to Designing Programs
  • 14. Mobile Development • Software Development Kit (SDK) – Emulator, Documentation, Tools, Services, etc. • Integrated Development Environment (IDE) • IDE Plugins
  • 15. Are you ready? Set your environments! http://www.cejug.org/display/cejug/Ambiente+para+os+mini- cursos+de+JavaME+e+Android
  • 16. Welcome to the… JavaME Development
  • 17. Introduction • Java Platform, Micro Edition – Java Community Process (JCP) based – Java Specification Request (JSR) • Reference Implementation (RI) • Test Compatibility Kit (TCK) • Proprietary APIs • Native Applications • Since 2000 • 80% handsets: 1.2bi phones, 1200 models, 180 carriers
  • 18. Architecture • JVM, KVM Source: SDN - java.sun.com/javame
  • 19. Core APIs • Configuration – CLDC, CDC, BD-J • Profile – MIDP, IM, PP, PBP, FP • Umbrella – Fragmentation: Computational, Physical, Functional – JTWI, MSA (Full, Subset)
  • 20.
  • 21. Development Infrastructure • Many environments: handset dependency • For this lab: – SDK: Sun WTK 2.5.2, JME SDK 3.0 – IDE: Eclipse Ganymede (3.4) – Plugin: Mobile Tools for Java 0.9 • Unified Emulator Interface (UEI)
  • 22. Hello JavaME World! • build, obfuscate, preverify, run, debug, and deploy • Create a project • Project structure • Create a MIDlet – javax.microedition.midlet.MIDlet • Over the Air (OTA) / installation • On Device Deployment/Debug • MIDlet.this.platformRequest(“tel:*”)
  • 23. MIDlet Lifecycle • Application Management Software (AMS) – Java Application Manager (JAM) • notifyDestroyed() • notifyPaused() • resumeRequest()
  • 24. MIDlet Lifecycle Coding import javax.microedition.midlet.MIDlet; public class HelloWorld extends MIDlet { public HelloWorld() { System.out.println(“MIDlet constructorquot;); } protected void destroyApp(boolean arg0) { System.out.println(quot; MIDlet destroyApp()quot;); } protected void pauseApp() { System.out.println(quot; MIDlet pauseApp()quot;); } protected void startApp() { System.out.println(quot; MIDlet startApp()quot;); } }
  • 25. Application Packaging • Profile dependent • MIDlet Suite – Java ARchive (.JAR) – Java Application Descriptor (.JAD) • Package generation
  • 26. Application Configuration • Java Application Descriptor (.JAD), Manifest • MIDlets • Permissions • Properties: – System System.getProperty(“javax.microedition.*”) – Application MIDlet.this.getAppProperty(quot;propertyNamequot;)
  • 27. Code Optimization • Free objects • String Vs. StringBuffer • Arrays Vs. Collection • Moderate use – Synchronized – Instance variables – Parameter number – Resources initiation – Interfaces, internal classes • JAR obfuscation, compression
  • 28. GUI Source: IBM - ibm.com
  • 29. GUI Coding public class HelloWorld extends MIDlet { private Display display; private Form myForm; // initialization on MIDlet constructor public startApp() { display = Display.getDisplay(this); // display.getCurrent(); display.setCurrent(myForm); } ... }
  • 30. Keyboard Handling • Components – javax.microedition.lcdui.CommandListener – javax.microedition.lcdui.Command • Registration – setCommandListener(CommandListener l) • Notification – commandAction(Command c, Displayable d) {} • Potential deadlock: operations such as IO and networking should run on a separate thread
  • 31. Keyboard Handling Coding public class HelloWorld extends MIDlet { Displayable d = new TextBox(“Title”, “Body”, 20,TextField.ANY); Command c = new Command(“Exit”, Command.EXIT, 0); d.addCommand(c); d.setCommandListener(new CommandListener() { public void commandAction(Command c, Displayable s) { doSomeAction(); } } ); }
  • 32. Persistent Storage • Record Management System (RMS) – javax.microedition.rms.* • RecordStore • RecordEnumeration • RecordComparator • RecordFilter
  • 33. Persistent Storage Coding ... RecordStore rs = null; String value = quot;Java ME in actionquot;; ... try { rs = RecordStore.openRecordStore(“RecName”, true); byte[] recData = value.getBytes(); rs.addRecord(recData, 0, recData.length); String data = new String(rs.getRecord(1)); } catch (Exception e) { ... }
  • 34. Connectivity • Generic Connection Framework (GCF) – javax.microedition.io.* • Remote (Infrastructured) – HTTP, HTTPS – TCP, UDP – Wireless Messaging (JSR120, 205) – Push Registry (MIDP) – SIP (JSR180) • Local (Ad hoc) Source: SDN - java.sun.com/javame – JABWT (JSR 82) – Ad Hoc Networking API (JSR 259)
  • 35. Connectivity Coding HttpConnection httpConn = null; InputStream = null; try { httpConn = (HttpConnection) Connector.open(quot;http://www.cejug.orgquot;); httpConn.setRequestMethod(HttpConnection.GET); httpConn.setRequestProperty(quot;User-Agentquot;, quot;Profile/MIDP-2.0 Configuration/CLDC 1.1quot;); is = httpConn.openInputStream(); int ch = -1; while((ch = is.read()) != -1){ ... } …
  • 36. References • Mobile and Embedded Guide to JavaOne 2008 – http://wiki.java.net/bin/view/Mobileandembedded/JavaO ne2008 • A Survey of Java ME Today – http://developers.sun.com/mobility/getstart/articles/surv ey/ • Java ME Device Table – http://developers.sun.com/mobility/device/ • JEDI course (DFJUG) – http://jedi.wv.com.br
  • 37. Welcome to the… Android Development
  • 38. Open Handset Alliance Manufactures Semiconductors Carriers Content Software
  • 39. Introduction • Software stack – Operating System • Linux Kernel (v2.6) – Middleware • Services – Applications HTC Dream (G1) • Java • Dalvik: custom virtual machine for embedded • Since 2008
  • 40. Characteristics • Applications… – without borders – are created equal – can run in parallel – can easily embed the web • Open source – http://source.android.com • Apache 2.0 and GLP v2 license
  • 42. Basic Components • Activity – UI component (Form like) typically corresponding to one screen • Intent Receiver – Set and respond to an external event: notifications or status changes. Can wake up your app • Services – Task without UI that runs in the background • Content Provider – Allow applications to share data
  • 43. Packages android.util android.telephony android.os android.hardware android.graphics android.text android.net.wifi android.database android.location android.content android.media android.view android.opengl android.widget android.app
  • 44. Development Infrastructure • Recommended environment • For this lab: – SDK: AndroidSDK 1.0 • QEMU-based (system image) – IDE: Eclipse Ganymede (3.4) – Plugin: Android Development Tool 0.8, WST • Add to environment variable PATH – tools directory • A lot of XML for application, activity, intent, layout, view, variable
  • 45. Hello Android World! • Create a project • Create an Activity – android.app.Activity • Project structure • LogCat • Deployment/Debug
  • 46. Application Configuration • AndroidManifest.xml • Application – Activity, Intent Filter • Permissions <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <manifest xmlns:android=quot;http://schemas.android.com/apk/res/androidquot; package=quot;org.cejug.androidquot; android:versionCode=quot;1quot; android:versionName=quot;1.0.0quot; android:screenOrientation=quot;landscapequot;> ...
  • 47. Application Anatomy • Activity – Can reuse functionality from other components by making a request in the form of an Intent – Can be replaced at any time by a new Activity with an equivalent IntentFilter • Intent – Request to do something: move from screen to screen. Activity.startActivity(myIntent) • Intent Filter – Description of Intent types
  • 48. Application Configuration ... <application android:icon=quot;@drawable/iconquot; android:label=quot;@string/app_namequot;> <activity android:name=quot;.HelloActivityquot; android:label=quot;@string/app_namequot;> <intent-filter> <action android:name=quot;android.intent.action.MAINquot; /> <category android:name=quot;android.intent.category.LAUNCHERquot; /> </intent-filter> </activity> <activity android:name=quot;.HelloListActivityquot; android:label=quot;ListActivityquot;> </activity> </application> </manifest>
  • 49. • Activities are stacked • Only one is active • Only one is open
  • 50. Application Coding public class HelloActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = new TextView(this); tv.setText(quot;Hello, Androidquot;); setContentView(tv); ... } } • onStart(), onResume(), onPause(), onStop(), onRestart(), onDestroy()
  • 51. SDK Tools • Emulator • Dalvik Debug Monitoring System (ddms) • Android Debug Bridge (adb) • Android Asset Packaging Tool (aapt) • Android Interface Description Language (aidl) • sqlite3 • Traceview • mksdcard • dx, activitycreator, and others
  • 52. Application Packaging/Deployment • APK file – .DEX • Log into a Linux server via a shell • Installation – adb install Application.apk – Uninstall • adb shell (remove file from /data/app/)
  • 53. GUI • Define in: code or XML • res/layout • Views – Text, Edit, List – Image, Web, Map • Layouts – Frame, Linear, Relative, Table, Absolute
  • 54. res/layout/main.xml - Views <LinearLayout xmlns:android=quot;http://schemas.android.com/apk/res/androidquot; android:orientation=quot;horizontalquot; android:layout_width=quot;fill_parentquot; android:layout_height=quot;wrap_contentquot; android:background=quot;@drawable/iconquot;>
  • 55. res/layout/main.xml - Layouts <Button android:id=quot;@+id/callButtonquot; android:layout_width=quot;fill_parentquot; android:layout_height=quot;wrap_contentquot; android:text=quot;Show Dialerquot; /> <EditText android:id=quot;@+id/phoneNumberquot; android:layout_width=quot;fill_parentquot; android:layout_height=quot;wrap_contentquot; />
  • 56. Event Handling Coding … final EditText phoneNumber = (EditText) findViewById(R.id.phoneNumber); Button callButton = (Button) findViewById(R.id.callButton); callButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent CallIntent = new Intent(Intent.ACTION_CALL, Uri .parse(quot;tel:quot; + “+5585quot; + phoneNumber.getText())); CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(CallIntent); } });
  • 57. Emulator: No support for… • Placing or receiving actual phone calls • USB connections • Camera/video capture (input) • Audio input • Determining connected state • Determining battery charge level / AC state • Bluetooth
  • 58. References • Android Documentation – http://code.google.com/android • Android A Programmers Guide (Jerome DiMarzio, Mc Graw Hill) • Professional Android Application Development (Reto Meier, Willey Publishing) • Many sites, forums, videos, screencasts, presentations…
  • 59. Would you like to be challenged? Practice matters!
  • 60. Challenge Requirements • Based on our lab practice • Create an application on JavaME or Android platform following the requirement – Receive a user text input through a wizard
  • 62. Thank you! Vando Batista vandofb at gmail.com msn: vfbatista at hotmail.com skype: vfbatista