Posts

Showing posts from February, 2022

Difference between View and ViewGroups

Image
Overview Image Credit - Geeks for Geeks Reference https://www.geeksforgeeks.org/difference-between-view-and-viewgroup-in-android/

Soap Services in Android Studio

Image
Overview SOAP stands for Simple Object Access Protocol. It's an XML based protocol for accessing webservices over HTTP. It could be used across all applications. As it is web based it is platform independent. Code android :usesCleartextTraffic ="true" <uses-permission android :name ="android.permission.INTERNET" /> class ConstantString { companion object { const val SOAP_ACTION : String = "http://www.w3schools.com/webservices/" const val NAME_SPACE : String = "http://www.w3schools.com/webservices/" const val URL : String = "http://www.w3schools.com/webservices/tempconvert.asmx" const val F_TO_C_METHOD_NAME : String = "FahrenheitToCelsius" const val C_TO_F_METHOD_NAME : String = "CelsiusToFahrenheit" const val F_TO_C_SOAP_ACTION : String = SOAP_ACTION + F_TO_C_METHOD_NAME const val C_TO_F_SOAP_ACTION : String = SOAP_ACTION + C_TO_F_METHOD_NA

FragmentStatePagerAdapter in Android

Image
Overview FragmentStatePagerAdapter is used to communicate between fragments. FragmentStatePagerAdapter is deprecated by the way. Example of FragmentStatePagerAdapter <androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".MainActivity" > <androidx.viewpager.widget.ViewPager android :id ="@+id/viewpager" android :layout_width ="match_parent" android :layout_height ="match_parent" /> </androidx.constraintlayout.widget.ConstraintLayout> class FragmentAdapter( private val fragmentManager : FragmentManager) : FragmentStatePagerAdapter(fragmentManager

BioMetrics in Android Studio

Image
Overview Biometric login provides a way to authorize access to private content.  Code for Fingerprint Scanning implementation "androidx.biometric:biometric:1.1.0" <uses-permission android :name ="android.permission.USE_BIOMETRIC" /> class BioMetricUtil( private val context : Context) { private lateinit var biometricPrompt : BiometricPrompt private lateinit var biometricPromptInfo : BiometricPrompt.PromptInfo private val tvText : TextView = ( context as MainActivity).findViewById(R.id. tvText ) private val btnLogin : Button = ( context as MainActivity).findViewById(R.id. btnLogin ) init { setBioMetric() } private fun setBioMetric () { val biometricManager : BiometricManager = BiometricManager.from( context ) when (biometricManager.canAuthenticate( BIOMETRIC_STRONG )) { BiometricManager. BIOMETRIC_SUCCESS -> { tvText . text = "You can use the f

Memory Management in Android

Image
Overview Use this code to check if device has low memory. override fun onStart () { super .onStart() val activityManager = getSystemService(Context. ACTIVITY_SERVICE ) as ActivityManager val memoryInformation = ActivityManager.MemoryInfo() activityManager.getMemoryInfo(memoryInformation) val totalMemory = memoryInformation. availMem val megaByte = totalMemory / ( 1024L * 1024L ).toInt() if (Build.VERSION. SDK_INT == Build.VERSION_CODES. M && (megaByte < 300 )) { Toast.makeText( this , "Insufficient Memory to run the application" , Toast. LENGTH_LONG ) .show() } else { Log.e( "Memory size" , "checkLowMemory: $ megaByte " ) } } Reference https://developer.android.com/topic/performance/memory

CameraX in Android

Image
Overview CameraX is a part of JetPack library which makes it easier to add camera capabilities in your application.  Reference https://developer.android.com/jetpack/androidx/releases/camera https://www.geeksforgeeks.org/how-to-create-custom-camera-using-camerax-in-android/

Offline Caching in Android Studio

Image
Overview Hello World Code plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'dagger.hilt.android.plugin' } // Dagger Hilt def hilt_version = "2.38.1" implementation "com.google.dagger:hilt-android: $hilt_version " kapt "com.google.dagger:hilt-compiler: $hilt_version " // Retrofit def retrofit_version = "2.9.0" implementation "com.squareup.retrofit2:retrofit: $retrofit_version " implementation "com.squareup.retrofit2:converter-gson: $retrofit_version " implementation "com.squareup.okhttp3:logging-interceptor:4.9.1" // Coroutines def coroutines_version = "1.6.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core: $coroutines_version " implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android: $coroutines_version " // ViewModel and LiveData def lifecycle_version = "2.4.0"

Common Issues of Android Studio

Image
Unrecognized Android Studio Version Reference:  https://stackoverflow.com/questions/68215266/unrecognized-android-studio-version Installed Build Tools revision 32.0.0 is corrupted. Remove and install again using the SDK Manager. Reference:  https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted

Git Introduction and command lines

Image
Steps to create GitHub Repository Create a GitHub Account Create a new Repository on the GitHub Account Create a new Project on Desktop or Laptop Install Git Bash Locate the folder of the project and open Git Bash here Use git init to track the project Use git statu s to check the files which we were about to add.  Then use git add . / git add -A to stage all the files in the current branch of the repository. Now use git status to check if all the files are staged. Then use git commit -m "commit-name" to commit the files to the branch of the repository and use git status to confirm there is nothing else to commit. Then use git remote add origin "url"  to connect the remote repository. Once the repository is connected, use git push -u origin "branch-name" to push the files in the branch of the repository.  Basic Commands git --version - Shows the version of Git. git config - Shows the configuration of Git. git config --global user.name "xxxxxx