Share
Embed
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
Transcript
44 slides
-
Should we request it? Request it! Do we have it?
Permissions Can we handle the result? Do what we need! -
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 -
Show me the code private val requestPermissionsContracts = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions()
) { permissions -> permissions.entries.forEach { if (it.key.contains("FINE")) { /** DO THINGS **/ } else { /** DO THINGS **/ } } } -
Show me the code private val requestPermissionsContracts = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions()
) { permissions -> permissions.entries.forEach { if (it.key.contains("FINE")) { /** DO THINGS **/ } else { /** DO THINGS **/ } } } -
Show me the code private val wantedPermissions = arrayOf( Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION ) -
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 } -
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 -
Intent To wire the Receiver Pending Intent Create the IntentSender
Broadcast Receiver Receives the result How does it work? -
Show me the code class ShareComponentReceiver : BroadcastReceiver() { override
fun onReceive( context: Context, intent: Intent ) { val chosenApp = intent.extras ?.get(EXTRA_CHOSEN_COMPONENT) .toString() } } -
Show me the code class ShareComponentReceiver : BroadcastReceiver() { override
fun onReceive( context: Context, intent: Intent ) { val chosenApp = intent.extras ?.get(EXTRA_CHOSEN_COMPONENT) .toString() } } -
Show me the code private fun shareIntent() = Intent().apply {
action = Intent.ACTION_SEND putExtra(Intent.EXTRA_TEXT, "Sample text to share!") type = "text/plain" } -
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 } -
Network Request It holds the requirements Network Callback We still
want to know the info Connectivity Manager We still need it The new way -
Show me the code private fun networkCallback() = object :
ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { /** DO THINGS **/ } override fun onUnavailable() { /** DO THINGS **/ } } -
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? ) { } -
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 ) { } } -
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 ) { } } -
Show me the code val callbacks = LifecycleListener() supportFragmentManager .registerFragmentLifecycleCallbacks(callbacks,
true) supportFragmentManager .unregisterFragmentLifecycleCallbacks(callbacks) -
Create UI info Manage callbacks Can use biometric HW? Authentication
Create prompt Authenticate! -
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 **/ } -
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() -
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 **/ } }