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

More Decks by Aung Kyaw Paing

Other Decks in Technology


  1. Aung Kyaw Paing (Vincent) Senior Consultant @ thoughtworks | GDE

    Thailand aungkyawpaing.dev Android API 101 A intro to Android for non-Android devs
  2. Android OS - Eventual Open source - Languages : Kotlin,

    Java & C - Run on Android Runtime (ART) - “Unused Memory is useless memory” principle
  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)
  4. Build System Android officially uses Gradle as its build system.

    However, you can also use other build systems like buck build.
  5. Activity Consider this an entry point for your app. It

    holds the UI that the user currently sees
  6. • 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
  7. • 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
  8. • Exposes data for other apps to use • Used

    for accessing system datas such as Contacts, Media etc.. Content Provider
  9. 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.
  10. //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))
  11. 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.
  12. A typical Manifest contains • Application Metadata • Components Definitions

    • Permission and Features requirements Android Manifest
  13. APK

  14. Splitting APK - CPU architecture - Screen density You can

    also generate a universal apk along with splitted apk
  15. Android App Bundle A publishing format that contains universal codes,

    and let Google Play do the split and signing
  16. 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,
  17. Google App Signing Instead of signing your app, you generate

    an upload key, and Google uses this key to sign you instead.
  18. • 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
  19. ADB ADB opens a communication to your debug application. You

    can install this via brew or use android sdk platform-tools
  20. #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
  21. # 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
  22. Typing Text adb shell input text user1 && adb shell

    input keyevent 61 adb shell input text password
  23. # 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
  24. adb shell am start -W -a android.intent.action.VIEW -d <URI> <PACKAGE>

    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
  25. 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/)