• Like
  • Save

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Droidcon: Sean Owen: Driving Downloads via Intents- 29/10/2010

  • 1,007 views
Uploaded on

Using intents, Apps can be used like a library or API. This can be a powerful way to drive downloads for some applications.

Using intents, Apps can be used like a library or API. This can be a powerful way to drive downloads for some applications.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,007
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Who has Barcode Scanner on their phone?

Transcript

  • 1. Driving Downloads via Intent
    Sean OwenCo-author “Barcode Scanner”
    Droidcon 2010
    29 October 2010
  • 2. Seen this app?
  • 3. A Brief History
  • 4. Barcode Scanner History
    Google NYC 20% project, 2 people, from early 2007
    Born as part of Print Ads
    Released as ZXingopen source project
    Just a demo app for camera API in Android 1.0
  • 5. A Testing Ground
    Camera API
    Preview, SurfaceView
    Focus, zoom, etc.
    Fast image processing
    Read/write contacts, bookmarks
    Wi-fi configuration …
    Intents
    Web – App integration
  • 6. Success through Openness
    < 1 person project
    10.3M installs, 6M active
    Growing ~33K per day
    #8 Android Market app
    Powers (directly or indirectly) most barcode apps for iPhone, Android and RIM
    1 rating : ~100 installs

  • 7. Success through Openness
    Makes Barcode Scanner a dependency
    Dependency drives downloads!
  • 8. Creating an Intent API
    (Developers only!)
  • 9. An Intent API
    Intent(ARG1, ARG2, …)
    startActivityForResult()
    setResult()
    Intent(RES1, RES2, …)
  • 10. Configure AndroidManifest.xml
    <activity ...>
    ...
    <intent-filter>
    <action android:name=“com.myapp.DO_IT”/>
    <category android:name=“
    android.intent.category.DEFAULT”/>
    </intent-filter>
    ...
    </activity>
  • 11. Caller invokes via Intent
    static final int DO_IT_RESULT = 0xDEADBEEF;
    Intent doIt =
    new Intent(“com.myapp.DO_IT”);
    doIt.addCategory(Intent.CATEGORY_DEFAULT);
    doIt.putExtra(“ARG1”, arg1);
    startActivityForResult(doIt, DO_IT_RESULT);
  • 12. Handle Intent in Activity
    public void onResume() {
    Intent intent = getIntent();
    String action = intent.getAction();
    if (“com.myapp.DO_IT”.equals(action))) {
    String arg1 =
    intent.getStringExtra(“ARG1”);
    // Do that something
    ...
    }
    ...
    }
  • 13. Return result via Intent
    Intent reply = new Intent(action);
    // Put result values as Intent “extras”
    reply.putExtra(“RES1”, res1);
    reply.putExtra(“RES2”, res2);
    setResult(RESULT_OK, reply);
    finish();
  • 14. Caller receives reply
    public void onActivityResult(
    int request, int result, Intent reply) {
    if (request == DO_IT_REQUEST &&
    result == RESULT_OK) {
    String res1 = reply.getExtra(“RES1”);
    String res2 = reply.getExtra(“RES2”);
    // Process result
    ...
    }
    }
  • 15. Punchline: Drive Downloads
    ActivityNotFoundExceptionon startActivityForResult() if app is not installed
    Caller sends user to Market to download instead
    Provide code and examples so caller gets it right(see android-integration/)
  • 16. Direct to Download
    startActivityForResult(...);
    } catch (ActivityNotFoundExceptionanfe) {
    // Prompt user with AlertDialog
    // If user clicks “Yes”:
    Uri uri = Uri.parse(
    "market://search?q=pname:com.myapp");
    Intent intent =
    new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
    }
  • 17. Creating a Web API
  • 18. Configure AndroidManifest.xml
    <activity ...>
    ...
    <intent-filter>
    <action android:name=“android.intent.action.VIEW”/>
    <category android:name=“
    android.intent.category.DEFAULT”/>
    <category android:name=“
    android.intent.category.BROWSABLE”/>
    <data android:scheme="http”
    android:host=”myapp.com”
    android:path="/doIt"/>
    </intent-filter>
    ...
    </activity>
  • 19. Site invokes via link
    <a href=“http://myapp.com/doIt?ARG1=arg”>
    Do it</a>
    Return informational page at http://myapp.com/doIt ; automatically shows when app not yet installed!
    MyApp!
  • 20. Handle Intent in Activity
    public void onResume() {
    Intent intent = getIntent();
    String ds = intent.getDataString();
    if (ds.startsWith(
    “http://myapp.com/doIt”) {
    Uri uri = Uri.parse(ds);
    String arg1 =
    uri.getQueryParameter(“ARG1”);
    // Do that something
    }
    ...
    }
  • 21. Return result via web Intent
    Uri uri = Uri.parse(
    “http://myapp.com/doneIt?RES1=res”);
    Intent reply = new Intent(
    Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(reply);
    finish();
  • 22. Site receives reply at URL
    http://myapp.com/doneIt?RES1=res1&RES2=res2
    RESULTS
    res1
    res2
  • 23. Think About Security
    Exposing an API can “leak” permissions
    Example: App which retrieves contacts via Intent
    Then any app can read contacts (without Android permission)!
    Think about abuses
    Is API consistent with users’ permission expectations?
  • 24. Why an API?
  • 25. Why an API?
    Can’t open source? Open an API
    API doesn’t have to mean free
    “Open” looks good and is good
    If you don’t, someone will
    1
  • 26. Why an API?
    Think platform, not just app
    Platforms get preinstalled
    Platforms are hard to uninstall
    Foothold for other services
    2
  • 27. Why an API?
    Drive downloads – and hence users
    Download is most of the battle
    Users try what’s on the phone
    Users stick with what they know
    3
  • 28. Further Reading
    code.google.com/p/zxing
    groups.google.com/group/zxing
    Barcode Scanner in Android Market
  • 29. Questions?