Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android API 101

Android API 101

An intro to Android for non-Android devs.

Aung Kyaw Paing

March 11, 2022
Tweet

More Decks by Aung Kyaw Paing

Other Decks in Technology

Transcript

  1. Aung Kyaw Paing (Vincent)
    Senior Consultant @ thoughtworks | GDE Thailand
    aungkyawpaing.dev
    Android API 101
    A intro to Android for non-Android devs

    View Slide

  2. Android OS
    - Eventual Open source
    - Languages : Kotlin, Java & C
    - Run on Android Runtime (ART)
    - “Unused Memory is useless memory” principle

    View Slide

  3. Android App
    - Sandboxed, every app creates it own users, i.e different
    users cannot see each other’s content
    - Unique application identifier (Reverse domain names)
    - Install via Android Package format (APK)

    View Slide

  4. Build System
    Android officially uses Gradle as its build system. However,
    you can also use other build systems like buck build.

    View Slide

  5. Android Components

    View Slide

  6. ● Activities
    ● Service
    ● Broadcast Receiver
    ● Content Provider
    4 Main Components in Android API

    View Slide

  7. Activity
    Consider this an entry point
    for your app. It holds the UI
    that the user currently sees

    View Slide

  8. ● Entry point for background tasks
    ● Foreground services where user is aware of (music playback,
    uploading a document.. etc), cannot be killed by System.
    ● Background service where user is not aware of (syncing data quietly),
    can be killed by System
    Service

    View Slide

  9. ● Receives events emitted by system (and other apps) such as dialing,
    low battery etc.
    ● Used mostly for alarm-based tasks or reacting to system changes
    Broadcast Receivers

    View Slide

  10. ● Exposes data for other apps to use
    ● Used for accessing system datas such as Contacts, Media etc..
    Content Provider

    View Slide

  11. Activating Components
    Components are activated through Intent (with the exception of
    Content Provider. Intent is the API that tells the system what the user
    wants to do.

    View Slide

  12. //Tell system user want to view url
    val intent = Intent(Intent.ACTION_VIEW).apply {
    data = "http://www.example.com".toUri()
    }
    startActivity(intent)
    //Staring a service
    val serviceIntent = Intent(this, MyService::class.java)
    startService(serviceIntent) //or startForegroundService()
    //Register battery low events (you can also do this via Manifest)
    registerReceiver(BatteryLevelReceiver(),
    IntentFilter(Intent.ACTION_BATTERY_CHANGED))

    View Slide

  13. Android Manifest

    View Slide

  14. View Slide

  15. Android Manifest
    An XML file that tells the OS everything about your app;
    what it is, what features does it use, what are the entry
    points… etc.

    View Slide

  16. A typical Manifest contains
    ● Application Metadata
    ● Components Definitions
    ● Permission and Features requirements
    Android Manifest

    View Slide

  17. android:name=".PhotoViewerActivity"
    android:exported="true">





    View Slide


  18. android:required="true"/>

    View Slide

  19. APK

    View Slide

  20. What’s inside an APK?
    - Manifest
    - DEX file (compiled code)
    - Resources
    - Assets

    View Slide

  21. Decompile/Reverse Engineering
    https://github.com/skylot/jadx https://developer.android.com/studi
    o/debug/apk-analyzer

    View Slide

  22. Splitting APK
    - CPU architecture
    - Screen density
    You can also generate a
    universal apk along with
    splitted apk

    View Slide

  23. Android App Bundle
    A publishing format that contains universal codes, and let Google Play do the
    split and signing

    View Slide

  24. APK ownership
    Each app is signed by a unique
    keystore+pass, where each keystore can
    have different alias+pass. If someone steal
    and modify the content, they cannot use
    the same keystore, and republish on
    stores and devices,

    View Slide

  25. Google App Signing
    Instead of signing your app, you generate an upload key, and Google uses this
    key to sign you instead.

    View Slide

  26. ● Don’t need to worry about
    losing/managing keystore file
    ● Better Security
    ● App Bundle has Instant Apps,
    Dynamic Features
    Google App Signing
    Pros
    ● How can we know for sure Google
    won’t modify the contents?
    ● Platform tied-in
    ● App Bundle causes crash in some
    devices
    Cons
    https://commonsware.com/blog/2020/09/23/uncomfortable-questions-app-signing.html

    View Slide

  27. Android Debug Bridge
    (ADB)

    View Slide

  28. ADB
    ADB opens a communication to your debug application.
    You can install this via brew or use android sdk
    platform-tools

    View Slide

  29. adb pair 192.168.0.242:38157
    Wireless Debugging

    View Slide

  30. #Push a file to Device
    adb push $FILE_IN_YOUR_PC$ $PATH_IN_YOUR_DEVICE$
    adb push ~/document.txt /sdcard/document.txt
    #Pull a file from Device
    adb pull $FILE_IN_YOUR_DEVICE$ $FILE_IN_YOUR_PC$
    adb pull /sdcard/document.txt ~/document.txt
    Transfer to/from device

    View Slide

  31. # Input text
    adb shell input text user1
    # Input Key Events (Enter, Tab etc)
    adb shell input keyevent 61
    # Pro tips : define aliases
    alias testLogin=adb shell input text user1 && adb shell input keyevent 61 adb
    shell input text password
    Typing Text

    View Slide

  32. Typing Text
    adb shell input text user1 && adb shell input keyevent 61 adb shell input text password

    View Slide

  33. # Screenshot
    adb shell screencap $PATH_IN_DEVICE
    # Record video
    adb shell screenrecord $PATH_IN_DEVICE
    # Pro tips: pull screen record
    adb shell screenrecord $PATH_IN_DEVICE
    adb shell pull $PATH_IN_DEVICE
    Screenshot & Screen record

    View Slide

  34. adb shell am start
    -W -a android.intent.action.VIEW
    -d
    adb shell am start
    -W -a android.intent.action.VIEW
    -d "https://example.com" com.google.chrome
    # Create an alias
    alias adOpenIntent=adb shell am start -W -a android.intent.action.VIEW -d
    Testing DeepLinks

    View Slide

  35. Recap
    ● 4 main components: Activity, Service, Broadcast Receiver & Content Provider
    ● Manifest tells your app’s capabilities to the OS
    ● Never lose your keystore
    ● Weigh the pros and cons of app bundle & play app signing
    ● Utilize ADB for efficiency in your work
    (Shameless plug: https://www.aungkyawpaing.dev/useful-adb-commands/)

    View Slide

  36. Q & A

    View Slide