How‌ ‌to‌ C‌reate a Toll Free Calling Application with Kotlin‌

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

  • Android Studio version 3.6.1
  • Little bit XML and KOTLIN knowledge
  • Android Emulator (or) Android mobile

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.

This is image title

Step 2

Now, add the activity and click the “Next” button.

This is image title

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.

This is image title

Step 4

Go to the manifest file. Add the dependency for calling Intent.

This is image title

The Manifest code is given below:

<uses-permission android:name="android.permission.CALL_PHONE" />   

Step 5

Go to Drawable file. Add ic_call_black.xml to show the call button.

This is image title

The XML code is given below:

<vector android:height="24dp" android:tint="#FFFFFF"  
   android:viewportHeight="24.0" android:viewportWidth="24.0"  
   android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">  
   <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"/>  
</vector>   

Step 6

Go to activity_main.xml. This XML file contains the design code for your Android app.

This is image title

The XML code is given below:

<?xml version="1.0" encoding="utf-8"?>  
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">  
   <com.google.android.material.floatingactionbutton.FloatingActionButton  
      android:id="@+id/fab"  
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:layout_gravity="bottom|end"  
      android:layout_margin="18dp"  
      android:src="@drawable/ic_call_black_24dp" />  
</androidx.coordinatorlayout.widget.CoordinatorLayout>   

Step 7

Go to Main Activity.kt. This Kotlin program is the back-end language for your app.

This is image title

The Kotlin code is given below:

package com.example.myapplication  
import android.Manifest  
import android.annotation.SuppressLint  
import android.content.Intent  
import android.content.pm.PackageManager  
import android.net.Uri  
import android.os.Bundle  
import androidx.appcompat.app.AppCompatActivity  
import androidx.core.app.ActivityCompat  
import kotlinx.android.synthetic.main.activity_main.*class MainActivity: AppCompatActivity() {  
    val phone = "1075"  
    val RequestCode = 1  
    override fun onCreate(savedInstanceState: Bundle ? ) {  
        super.onCreate(savedInstanceState)  
        setContentView(R.layout.activity_main)  
        fab.setOnClickListener {  
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {  
                ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE), RequestCode)  
            } else {  
                startcall()  
            }  
        }  
    }  
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array < out String > , grantResults: IntArray) {  
        if (requestCode == RequestCode) startcall()  
    }  
    private fun startcall() {  
        val callIntent = Intent(Intent.ACTION_CALL)  
        callIntent.setData(Uri.parse("tel:" + phone))  
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {  
            return  
        }  
        startActivity(callIntent)  
    }  
}   

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

This is image title

This is image title

This is image title

#kotlin #java #mobile app development #programming

How‌ ‌to‌ C‌reate a Toll Free Calling Application with Kotlin‌
6.15 GEEK