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.

0991ca4bc363163337f7b02b98af538a?s=128

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
  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. Android Components

  6. • Activities • Service • Broadcast Receiver • Content Provider

    4 Main Components in Android API
  7. Activity Consider this an entry point for your app. It

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

    for accessing system datas such as Contacts, Media etc.. Content Provider
  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.
  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))
  13. Android Manifest

  14. None
  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.
  16. A typical Manifest contains • Application Metadata • Components Definitions

    • Permission and Features requirements Android Manifest
  17. <activity android:name=".PhotoViewerActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.ACTION_VIEW" /> <data android:mimeType="image/*" />

    </intent-filter> </activity>
  18. <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/> <uses-feature android:name="android.hardware.bluetooth" android:required="true"/>

  19. APK

  20. What’s inside an APK? - Manifest - DEX file (compiled

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

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

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

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

    an upload key, and Google uses this key to sign you instead.
  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
  27. Android Debug Bridge (ADB)

  28. ADB ADB opens a communication to your debug application. You

    can install this via brew or use android sdk platform-tools
  29. adb pair 192.168.0.242:38157 Wireless Debugging

  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
  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
  32. Typing Text adb shell input text user1 && adb shell

    input keyevent 61 adb shell input text password
  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
  34. 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
  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/)
  36. Q & A