DEV Community

Aditya Oberai
Aditya Oberai

Posted on • Updated on

Fake a Phone Call from Wear OS Smartwatches using Xamarin, Azure Functions, and Twilio

We have all been in that situation where we are stuck chatting with someone we want to run away from but we can't. It could be at a party, a convention, anywhere basically, but it happens.

this is so frustrating gif

At that point, all that we hope for is someone's phone call to let you pull yourself away from the absolute madness you have to deal with in the name of social behaviour!

At that moment, you can never know whether your saviour shall appear in the form of a tring tring from your phone, but what if I told you that you could make that "call" happen without someone else calling you anyway?

Chris Pratt surprised gif

Ladies and gentlemen, I present to you all...πŸ₯πŸ₯πŸ₯

πŸ•΅οΈβ€β™‚οΈ FakeACall πŸ“²

FakeACall is an application that I made for my Wear OS by Google smartwatch to fake a phone call to my phone to get out of tricky situations. It has been built with Xamarin.Android and uses an Azure Function and Twilio Programmable Voice to achieve this aim.

FakeACall

The best part about this app is that we can all build it for ourselves. And that's exactly what we're going to do now!!!

Step 1: Understand the Application Flow

In this app, there will be two major components:

  • The Azure Function to call the Twilio Programmable Voice API
    • This will be responsible for making the phone call to your phone from your Twilio number
  • The Wear OS smartwatch app built using Xamarin.Android to call the Azure Function
    • This will be responsible for triggering the Azure Function to ensure that the call is made

FakeACall App Flow

Let's go ahead with developing our Azure Function first.

Step 2: Build an Azure Function to call the Twilio Programmable Voice API using .NET

Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running. Twilio Programmable Voice is Twilio's API that allows you to quickly make and receive voice calls in your application.

We will build an Azure Function to call the Twilio Programmable Voice API which will make a call to your mobile phone. For this task, you will need the following:

  • A Microsoft Azure Account
    • You can create an Azure account for free here. In case you're currently an enrolled student with a .edu email address, you can get $100 worth of Azure credits by availing the Azure For Students offer too.
  • A Twilio Account and Phone Number
    • Head over to the Twilio website and sign up for an account if you don't have one already. Add a phone number to your account that has calling and SMS capabilities. If you're a student, you can get $50 worth of Twilio credits for free through the GitHub Student Developer Pack. Read more about this here.
  • Visual Studio Code along with the relevant extensions
  • Azure Functions Core Tools version 3.x
    • Azure Functions Core Tools lets you develop and test your functions on your local computer from the command prompt or terminal. Your local functions can connect to live Azure services, and you can debug your functions on your local computer using the full Functions runtime. You can even deploy a function app to your Azure subscription. Please install Azure Functions Core Tools from here.
  • .NET Core 3.1
    • As we will be building our Azure Function with C# and .NET, you must install the .NET Core 3.1 SDK. You can build Azure Functions using other languages such as Java, JavaScript, Python. etc. as well.

Note: In case you have never tried building an Azure Function with .NET, please check out this little tutorial.

Once we have all of our necessities, let's begin:

go time gif

  1. In VS Code, choose the Azure icon in the Activity bar, then in the Functions area, select the Create new project... icon.

VS Code Azure Functions Area

  1. Select a directory location for your project.

  2. Provide the following information at the prompts:

    1. Select a language for your function project: Choose C#
    2. Select a template for your project's first function: Choose HTTP trigger
    3. Provide a function name: Type FakeCall
    4. Provide a namespace: Type Company.Function
    5. Authorization level: Choose Anonymous
    6. Select how you would like to open your project: Open in current window

VS Code will use all this info to generate an Azure Functions project with an HTTP trigger.

Once that is done, navigate over to the FakeCall.cs file visible in your directory and replace the existing template with the following code:

This Azure Function here will utilise the Twilio SDK for C# and .NET to interact with the Voice API and make a phone call.

Make sure that you install the Twilio NuGet package using the .NET Core command-line tools by running the following command in your command prompt/shell:

dotnet add package Twilio
Enter fullscreen mode Exit fullscreen mode

You will also have noticed that there are 4 environment variables:

  • TWILIO_ACCOUNTSID: The Account SID from your Twilio dashboard
  • TWILIO_AUTHTOKEN: The Auth Token from your Twilio dashboard
  • NUMBERTOCALL: The phone number you intend to call, i.e. your own phone number
  • TWILIO_PHONENO: The Twilio phone number you added to your account

We will add these to our Azure Function App in the portal after deployment. To do that, complete the following steps:

  1. Choose the Deploy to function app... button in the Functions area we visited earlier

VS Code Azure Functions Area

  1. Provide the following information at the prompts:

    1. Select subscription: Choose the subscription to use (you won't see this if you only have one subscription)
    2. Select Function App in Azure: Choose - Create new Function App
    3. Enter a globally unique name for the function app: Type a name that is valid in a URL path
    4. Select a location for new resources: For better performance, choose a region near you.
  2. Select View Output in the notification that will appear to view the creation and deployment result. You will be able to find the URL generated for the function here. If you miss the notification, select the bell icon in the lower right corner to see it again.

We also have to add the environment variables to our Azure Function, so log in to the Azure portal, visit your Function App, and find Configuration under Settings in the left pane. You can add your environment variables there as a New application string.

Function Application Strings

And our Azure Function is ready to run! You can send either a GET or a POST HTTP Request to the Function URL and it will call your phone.

Denzel Washington Reaction GIF

Let us now build the Wear OS app for our smartwatch that we will use to call this Azure Function and thus, fake a phone call.

Step 3: Build the Wear OS smartwatch app with Xamarin.Android

Xamarin is an open-source platform for building modern and performant applications for iOS, Android, and Windows with .NET.

We will build a Wear OS app using Xamarin.Android, which, for our smartwatch now to call the Azure Function we just built. For this task, you will need the following:

  • Visual Studio IDE with Mobile development with .NET workload
    • Visual Studio is the officially supported IDE for Xamarin development. If you have not yet, go ahead and install the Community edition for free from here. When setting it up, download and install the Mobile development with .NET workload, which will install all Xamarin-related components. Once you do that, you will need to verify that you have the right versions of Xamarin.Android, Android SDK, and Java JDK installed. You can find the minimum requirements needed to build a Wear OS app here.

Note: In case you have never tried building a Wear OS smartwatch app, do try the Hello, Wear tutorial.

Now we can go ahead, create a new project using the Android Wear App (Xamarin) template and name the solution FakeACall.

Xamarin Project Creation

As soon as that is done, let's get coding:

cat coding gif

  1. Create the UI

    Visit the ./Resources/layout folder in the app directory, open the activity_main.xml file and replace the template with the following code:

    What we're essentially doing here is adding a Button with some text. This text will change when the application runs in order to notify you whether the call occurred successfully or not.

    As soon as that is done, we will go ahead and create the backend for the app.

  2. Create the backend

Go over to the MainActivity.cs file in the app directory and replace the template with the following code:

Here, we are making a POST HTTP Request to our Azure Function and then closing the app automatically once the app notifies us whether the app sent the POST Request successfully or not.

Make sure that you install the following NuGet packages using the NuGet Package Manager through Visual Studio:

Once this step is complete, your app is ready for testing.

self fice gif

Step 4: Test the app and enjoy

You can now go ahead and test your app. Debugging the app on your Wear OS device instead of the emulator will deploy it there for usage later too, so you can do that instead by following the instructions here. In case you do so, make sure that your Wear OS device is connected to your smartphone before you run the app. I will recommend saving the Twilio number as a contact to make your fake call seem more legitimate (for the demo, I saved it as Work Twilio).

If all has gone well, your experience will be the same as my demo:

And that is all for today folks!

If you reached the end, my heartiest congratulations to you!

One of the best parts about this app here is that the Azure Function can be called from any device capable of making HTTP requests, so you can extend this functionality to other platforms too. Slight tweaking of the message content in the Twilio API can also turn this into a very useful SOS app.

I sincerely hope this app will be able to help you in case you're stuck in any troublesome situation. I am sharing my original GitHub repo for this app below as well. If you like it, do show some love by giving it a ⭐

GitHub logo adityaoberai / FakeACall

Wear OS smartwatch app that can fake a phone call to get out of tricky situations

FakeACall

Banner


Description

FakeACall is an Android Wear application that allows the smartwatch owner to fake a phone call in order to get out of situations they may want to. It has been built using Xamarin.Android and uses an Azure Function and Twilio Programmable Voice to fake a phone call.

Components

  • The main branch contains the Xamarin.Android project used to build the Android Wear OS app.

  • The twilio_function branch contains the Azure Function that uses Twilio Programmable Voice to fake a call.


Demo

Recording


Learn How To Build It

You can learn how to build this app for yourself by reading the article here




Thank you so much for reading this article. Keep learning, building, sharing, and have a great day! ❀

Top comments (6)

Collapse
 
ulrichgood profile image
ulrichgood • Edited

This FakeACall app is genius! I've been in those awkward situations too. Kudos for crafting a digital escape plan. I love how tech can save us from social craziness. I'm definitely gonna give this a spin for those "emergency" moments. I also already use whocalled.co.uk, and it's pretty handy. Thanks for the cool hack!

Collapse
 
adityaoberai profile image
Aditya Oberai

Haha thanks

Collapse
 
bijoy26 profile image
Anjum Rashid

Very detailed yet such an interesting idea to implement! More life hack solutions please!

Collapse
 
adityaoberai profile image
Aditya Oberai • Edited

Thank you for your kind words @bijoy26 πŸ˜„β€οΈ

Collapse
 
prathameshshanbhag profile image
Prathamesh Shanbhag

Never Imagined that A Fake Phone Call App had so much going on behind it, Thanks Aditya for sharing this, If I ever get a chance I will try to make such a project!
Really great article overall!❀❀

Collapse
 
adityaoberai profile image
Aditya Oberai

Thanks a ton @prathameshshanbhag πŸ˜πŸ™Œβ€οΈ