integrate android apps and web apps

18

Click here to load reader

Upload: commonsware

Post on 14-May-2015

402 views

Category:

Technology


3 download

DESCRIPTION

from the January 20Mobile+Web DevCon

TRANSCRIPT

Page 1: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Integrating Android Apps and Web Apps

Page 2: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Objective: Add Value

● App complements site, does not replace it– Different roles, different scenarios

● Support multiple screens– Browser on desktop interacting with app on

device● Single source

– App and site leverage same Web service back end

Page 3: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Objective– User clicks on link in Web site from mobile

browser– App pops up in response to that click

● Examples– Wikipedia– Barcode scanning

Page 4: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #1: Regular URL– Site has link to:

http://www.yourdomain.com/something– What App Has

● Activity to be displayed when that link is clicked● <intent-filter> advertising supporting VIEW action,

BROWSABLE category, and that URL

Page 5: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #1: Regular URL– What User Sees

● If app not installed: whatever is at that URL● If app is installed: chooser to use browser or app to

process the request (unless default already chosen)

– Passing Data● Additional path segments (with pathPrefix)● Query parameters

Page 6: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #1: Regular URL– Limitation: Chooser appears

● User can make your app be the default for this particular request, but still sees chooser the first time

● No way to avoid allowing a Web browser to handle an HTTP link

Page 7: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #2: Custom Scheme– Site has link to: yourscheme://something– What App Has

● Activity to be displayed when that link is clicked● <intent-filter> advertising supporting VIEW action,

BROWSABLE category, and that URL complete with custom scheme

Page 8: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #2: Custom Scheme– Pros

● No chooser!● Alignment with other operating systems

– Cons● Link is useless without app● Possible scheme collision

Page 9: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Web

● Strategy #3: Custom MIME Type– Site serves up content under distinct vendor

MIME type, that your app handles– Cons

● Effects not immediate: download first, tap on notification, then get into your app

● Possible MIME type collisions

● Overall Con: Assumes Browsing from the Device

Page 10: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Desktop Web

● Strategy #1: QR Codes– App displays QR code, user scans– Requires QR code-scanning app

● Barcode Scanner● Google Goggles● Etc.

Page 11: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Desktop Web

● Strategy #2: Push with GCM– Google Cloud Messaging– Push messages from your server to the device

● In response to actions within your Web app● In response to other conditions (e.g., reminders)

– Free!– Requires Android 2.2+, routing data through

Google servers

Page 12: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Desktop Web

● Strategy #2: Push with GCM– Client Side Steps

● Get an API key● Add GCM JAR to your libs/ directory● Add permissions● Register a GCM-supplied BroadcastReceiver● Implement an IntentService that handles events● Register the app when run● Send registration ID to your server

Page 13: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Launching App from Desktop Web

● Strategy #2: Push with GCM– Server Side Steps

● Find GCM server library● Create JSON of payload and other options● Send notification with payload and registration IDs

Page 14: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Getting to Web from App

● Option #1: ACTION_VIEW– Create an ACTION_VIEW Intent, with the URL

you wish to visit– Pass that to startActivity()– Result: default/chosen browser launched

Page 15: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Getting to Web from App

● Option #2: WebView– Embed WebView widget in layout, used by

activity or fragment● WebViewFragment available for API Level 11

fragments

– Configure WebView● e.g., JavaScript disabled by default

– Call loadUrl() with your URL– Result: your Web site in your app

Page 16: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Fancier Stuff

● Common Web Service– App plus “single page application” or equivalent– Works best with REST-style APIs (vs. SOAP, XML-

RPC, etc.)● OAuth

– Common authentication infrastructure for app, Web site

– App side tends to be a bit clunky

Page 17: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Fancier Stuff

● Common Implementation– Use same Web technologies on device as on

desktop– HTML5 app, PhoneGap, etc.

● “Throwing” Between Screens– Capture current session state, package up in way

that other environment can continue

Page 18: Integrate Android Apps and Web Apps

Copyright © 2013 CommonsWare, LLC

Speaker ContactInformation

SlideShare