Android Studio Tutorial – An App to Track Outgoing Calls

Hello friends, welcome again to this new android studio tutorial. In this android studio tutorial we will be creating a simple app to detect outgoing calls. So if you are struggling to create an app …

android studio tutorial

Hello friends, welcome again to this new android studio tutorial. In this android studio tutorial we will be creating a simple app to detect outgoing calls. So if you are struggling to create an app that can detect the outgoing calls; you just came to the right place. So without wasting time lets start our android studio tutorial.

[easy_media_download url=”https://dl.dropboxusercontent.com/s/6zscflnh3w8x81u/android-studio-tutorial-detecting-outgoing-calls.zip?dl=0″ text=”Download Source”]

Creating Android Studio Project

  • Open android studio and create a new project. I created DetectOutgoingCalls
  • Now you will get your MainActivity.java and activity_main.xml
  • We need a broadcast receiver that will detect the outgoing call

Creating Broadcast Receiver for Detecting Outgoing Calls

  • Right click on your package name. Go to new -> java class and create a new java class.
  • I just created CallDetector.java

  • Inside this class we will create a new class for our broadcast receiver

  • We will store the number received using Shared Preferences

  • Now we will create two methods, start and stop.
  • In start we will register our broadcast receiver and in stop we will unregister it
  • Including start stop method our full CallDetector class will be look as follow

  • Now the problem is we cannot make a call without minimizing our app
  • So if we minimize our app for making a call our app will not work
  • So we have to do something so that our app will work on background
  • We can overcome this problem by creating a service
  • Right click on your package -> new -> java class and create a new java class. I just created CallDetectionService
  • This class will extend the Service class, so we need to override some methods as well

  • Inside onStartCommand we will start our broadcast receiver and inside onDestroy we will stop our broadcast receiver
  • So the final code for CallDetectionService.java will be

  • Now we need to add this service to our manifest
  • Add the following code inside application tag in your manifest

  • Inside manifest add the following permission as well

  • Now the last part is to create a User Interface to make our app work.

Designing User Interface for Our Android Application

  • Come to your activity_main.xml. We need to create the following layout
android studio tutorial
User Interface
  • Use the following xml code for creating above layout

  • Now come to your MainActivity.java

  • Inside onClick we will toggle the detection

  • Now in onResume method we will fetch the data from shared preferences

  • Thats it now run your project. Click on the button then minimize your app and make a call. Now end the call and open the app you will see the number on the text view.

Check the Video of Tracking Outgoing Calls in Android

This is the video demonstration of the output of this android app.

So thats all for this android studio tutorial friends. Hope you enjoy this android studio tutorial. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x