How‌ ‌to‌ C‌reate a Toll-Free Calling Application Such as COVID-19 Customer Care Using Kotlin‌

Introduction

 
Android is an open-source operating system based on Linux with a Java programming interface for mobile devices such as Smartphone (Touch Screen Devices who supports Android OS) as well for tablets. With over 85% market share worldwide, Android Operating System dominates the mobile platform market. Today, I will show you how to create a toll-free calling Application such as COVID-19 customer care using Kotlin.
 
Requirements
Steps to follow:
 
Follow these steps to load the ImageURL to Imageview using Glide in Kotlin. I have included the source code in the attachment.
 
Step 1
 
Open Android Studio and start a new Android Studio Project.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
Step 2
 
Now, add the activity and click the "Next" button.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
Step 3
 
You can choose your application name and choose where your project is to be stored and choose Kotlin language for coding the project, Now, select the version of Android and select the target Android devices, and click the "Finish" button.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
Step 4
 
Go to the manifest file. Add the dependency for calling Intent.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
The Manifest code is given below:
  1. <uses-permission android:name="android.permission.CALL_PHONE" />   
Step 5
 
Go to Drawable file. Add ic_call_black.xml to show the call button.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
The XML code is given below:
  1. <vector android:height="24dp" android:tint="#FFFFFF"  
  2.    android:viewportHeight="24.0" android:viewportWidth="24.0"  
  3.    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">  
  4.    <path android:fillColor="#FF000000" android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z"/>  
  5. </vector>   
Step 6
 
Go to activity_main.xml. This XML file contains the design code for your Android app.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
The XML code is given below:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.    xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.    xmlns:tools="http://schemas.android.com/tools"  
  5.    android:layout_width="match_parent"  
  6.    android:layout_height="match_parent"  
  7.    tools:context=".MainActivity">  
  8.    <com.google.android.material.floatingactionbutton.FloatingActionButton  
  9.       android:id="@+id/fab"  
  10.       android:layout_width="wrap_content"  
  11.       android:layout_height="wrap_content"  
  12.       android:layout_gravity="bottom|end"  
  13.       android:layout_margin="18dp"  
  14.       android:src="@drawable/ic_call_black_24dp" />  
  15. </androidx.coordinatorlayout.widget.CoordinatorLayout>   
Step 7
 
Go to Main Activity.kt. This Kotlin program is the back-end language for your app.
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
The Kotlin code is given below:
  1. package com.example.myapplication  
  2. import android.Manifest  
  3. import android.annotation.SuppressLint  
  4. import android.content.Intent  
  5. import android.content.pm.PackageManager  
  6. import android.net.Uri  
  7. import android.os.Bundle  
  8. import androidx.appcompat.app.AppCompatActivity  
  9. import androidx.core.app.ActivityCompat  
  10. import kotlinx.android.synthetic.main.activity_main.*class MainActivity: AppCompatActivity() {  
  11.     val phone = "1075"  
  12.     val RequestCode = 1  
  13.     override fun onCreate(savedInstanceState: Bundle ? ) {  
  14.         super.onCreate(savedInstanceState)  
  15.         setContentView(R.layout.activity_main)  
  16.         fab.setOnClickListener {  
  17.             if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {  
  18.                 ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE), RequestCode)  
  19.             } else {  
  20.                 startcall()  
  21.             }  
  22.         }  
  23.     }  
  24.     override fun onRequestPermissionsResult(requestCode: Int, permissions: Array < out String > , grantResults: IntArray) {  
  25.         if (requestCode == RequestCode) startcall()  
  26.     }  
  27.     private fun startcall() {  
  28.         val callIntent = Intent(Intent.ACTION_CALL)  
  29.         callIntent.setData(Uri.parse("tel:" + phone))  
  30.         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {  
  31.             return  
  32.         }  
  33.         startActivity(callIntent)  
  34.     }  
  35. }   
Step 8
 
Next, click the "Run" button or press shift+f10 to finally run the project. Choose the "virtual machine" option and click OK.
 

Conclusion

 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌
 
How‌ ‌To‌ C‌reate A Toll Free Calling Application Like Covid-19 Customer Care Using Kotlin‌


Similar Articles