Skip to main content

Posts

Simple example of using firestore in Android | Kotlin

Here is the simple example of maintaining database using Firebase instead of SQLite in Kotlin Programming Language . Step 1. Login into Firebase Console and create your project. Step 2. Navigate into Database and follow the steps given there. Step 3. Create your Android project and add the following classpath into root of the project's build.gradle. classpath 'com.google.gms:google-services:3.1.1' Step 4. And then add the following plugin into your module's build.gradle. apply plugin: 'com.google.gms.google-services' Step 5. And then add the following dependency into your module's build.gradle. implementation 'com.firebaseui:firebase-ui-firestore:3.3.1' That's all you wanted to access the Firebase's Firestore API in your project. Here is the methods to create document(Like table in SQLite), Add data to document, edit data from document, delete data from document. Add data to document using Hashmap. //Create employee usin...

Simple Example of Firebase Authentication in Kotlin

Here is the simple example of Authentication process using Firebase in Kotlin Programming Language . Step 1. Login into Firebase Console and create your project. Step 2. Navigate into Authentication and enable your preferred login methods. Step 3. Create your Android project and add the following classpath into root of the project's build.gradle. classpath 'com.google.gms:google-services:3.1.1' Step 4. And then add the following plugin into your module's build.gradle. apply plugin: 'com.google.gms.google-services' Step 5. And then add the following dependency into your module's build.gradle. implementation 'com.firebaseui:firebase-ui-auth:3.3.1' That's you wanted to access the Firebase's Authentication API in your project. Here is the methods to Sign In, Sign Out and delete the account. Sign In private fun signIn() { // Choose authentication providers val providers = Arrays.asList(AuthUI.IdpConfig.GoogleBuilde...

Simple example of OCRReader in Android.

Hi Friends, Maybe you all heard/used text scanning using camera feature or extracting text from Image. But this sample made it very easy for you. You can made it in very simple line of code. You can download the source code from OCRSample and import the library as a module into your project. Example usage : MainActivity.java public class MainActivity extends AppCompatActivity { private TextView textView; private final int CAMERA_SCAN_TEXT = 0; private final int LOAD_IMAGE_RESULTS = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = findViewById(R.id.textView); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSele...

Simple example of using RadioGroup, RadioButton in Kotlin | Android

Here is the simple example of using RadioGroup, RadioButton in Android Kotlin. &ltRadioGroup xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/radioGroup" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.guna.kotlinapplication.BlankFragment"&gt &ltRadioButton android:id="@+id/radioMale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/male" /&gt &ltRadioButton android:id="@+id/radioFemale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/female" /&gt &lt/RadioGroup&gt OnCheckedChangeListener radioGroup.setOnChe...

Simple example of using Fragments in Kotlin | Android

Here is the simple example of using Fragments with Activity in Android. MainActivity.kt class MainActivity : AppCompatActivity(), BlankFragment.OnFragmentInteractionListener { override fun onFragmentInteraction(uri: Uri) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) setSupportActionBar(toolbar) if (savedInstanceState == null) { supportFragmentManager.beginTransaction(). add(R.id.fragment, BlankFragment.newInstance("Param1", "Param2"), "Second").commit() } fab.setOnClickListener { view -> //Here we will replace the BlanckFragment with SecondFragment. supportFragmentManager.beginTransaction().replace(R.id.fragment, SecondFragment(),...

Simple example of SeekBarPreference in Android

There is no predefined SeekBarPreference in Android. But we can make our own SeekBarPreference very simply. Here is simple example of making and using SeekBarPreference in Android. SeekBarPreference.java public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener { private TextView textValue; public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public SeekBarPreference(Context context, AttributeSet attrs) { super(context, attrs); } public SeekBarPreference(Context context) { super(context); } @Override protected View onCreateView(ViewGroup parent) { super.onCreateView(parent); View view = LayoutInflater.from(getContext()).inflate(R.layou...

Simple example of Using JobScheduler in Android

JobScheduler is the Android framework API for scheduling tasks or work. It first became available in Android 5.0 (API level 21), and remains under active development. Notably, Android 7.0 (API level 24) added the ability to trigger jobs based on ContentProvider changes. If your app targets Android 5.0 (API level 21), we recommend that you use the JobScheduler to execute background tasks. Here is the simple example of Scheduling and Cancelling the scheduled job. MainActivity.java public class MainActivity extends AppCompatActivity { int count; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); } public void addJob(View view) { count++; JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); ComponentName comp...