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

Fantastic API and where to find them

Fantastic API and where to find them

Slides of the talk I kept at:
- Mobile Z Days 2020 Online
- DevFest Italy 2020 Online

Roberto Orgiu

October 18, 2020
Tweet

More Decks by Roberto Orgiu

Other Decks in Technology

Transcript

  1. Should we request it? Request it! Do we have it?

    Permissions Can we handle the result? Do what we need!
  2. Should we request it? Request it! Do we have it?

    More permissions! Can we handle the result? Do what we need! INSERT COMPLICATED LOGIC HERE
  3. Show me the code private val requestPermissionsContracts = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions()

    ) { permissions -> permissions.entries.forEach { if (it.key.contains("FINE")) { /** DO THINGS **/ } else { /** DO THINGS **/ } } }
  4. Show me the code private val requestPermissionsContracts = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions()

    ) { permissions -> permissions.entries.forEach { if (it.key.contains("FINE")) { /** DO THINGS **/ } else { /** DO THINGS **/ } } }
  5. Show me the code class CustomContract : ActivityResultContract<Int, Boolean>() {

    override fun createIntent( context: Context, input: Int): Intent override fun parseResult( resultCode: Int, intent: Intent?): Boolean }
  6. Pick a contact Contacts Get content (or more), create or

    open a document, open multiple documents or a document tree Content Start Activities or Intent Senders for result System Take a picture, a preview, or a video Multimedia Request one or more permissions Permissions More use cases
  7. Intent To wire the Receiver Pending Intent Create the IntentSender

    Broadcast Receiver Receives the result How does it work?
  8. Show me the code class ShareComponentReceiver : BroadcastReceiver() { override

    fun onReceive( context: Context, intent: Intent ) { val chosenApp = intent.extras ?.get(EXTRA_CHOSEN_COMPONENT) .toString() } }
  9. Show me the code class ShareComponentReceiver : BroadcastReceiver() { override

    fun onReceive( context: Context, intent: Intent ) { val chosenApp = intent.extras ?.get(EXTRA_CHOSEN_COMPONENT) .toString() } }
  10. Show me the code private fun shareIntent() = Intent().apply {

    action = Intent.ACTION_SEND putExtra(Intent.EXTRA_TEXT, "Sample text to share!") type = "text/plain" }
  11. Show me the code private fun intentSender(): IntentSender { val

    receiverIntent = Intent( this, ShareComponentReceiver::class.java ) val pendingIntent = PendingIntent.getBroadcast( this, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT ) return pendingIntent.intentSender }
  12. Network Request It holds the requirements Network Callback We still

    want to know the info Connectivity Manager We still need it The new way
  13. Show me the code private fun networkCallback() = object :

    ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { /** DO THINGS **/ } override fun onUnavailable() { /** DO THINGS **/ } }
  14. Show me the code class LifecycleListener : FragmentManager.FragmentLifecycleCallbacks() { override

    fun onFragmentViewCreated( fm: FragmentManager, f: Fragment, v: View, savedInstanceState: Bundle? ) { } override fun onFragmentCreated( fm: FragmentManager, f: Fragment, savedInstanceState: Bundle? ) { }
  15. Show me the code savedInstanceState: Bundle? ) { } override

    fun onFragmentCreated( fm: FragmentManager, f: Fragment, savedInstanceState: Bundle? ) { } override fun onFragmentDestroyed( fm: FragmentManager, f: Fragment ) { } override fun onFragmentViewDestroyed( fm: FragmentManager, f: Fragment ) { } }
  16. Show me the code class LifecycleListener : FragmentManager.FragmentLifecycleCallbacks() { override

    fun onFragmentViewCreated( fm: FragmentManager, f: Fragment, v: View, savedInstanceState: Bundle? ) { } override fun onFragmentCreated( fm: FragmentManager, f: Fragment, savedInstanceState: Bundle? ) { } override fun onFragmentDestroyed( fm: FragmentManager, f: Fragment ) { } override fun onFragmentViewDestroyed( fm: FragmentManager, f: Fragment ) { } }
  17. Show me the code val biometricManager = BiometricManager.from(this) when (biometricManager.canAuthenticate())

    { BiometricManager.BIOMETRIC_SUCCESS -> /** DO THINGS **/ BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE, BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE, BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> /** ERROR **/ }
  18. Show me the code fun buildPromptInfo() = BiometricPrompt.PromptInfo .Builder() .setTitle("Biometric

    authentication sample.") .setSubtitle("I'm a subtitle.") .setDescription("I'm a description") .setNegativeButtonText("Cancel") .build()
  19. Show me the code fun callback() = object : BiometricPrompt.AuthenticationCallback()

    { override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { /** DO THINGS **/ } override fun onAuthenticationSucceeded(result: AuthenticationResult) { /** DO THINGS **/ } override fun onAuthenticationFailed() { /** DO THINGS **/ } }
  20. Q&A