Developing a Screen Mirroring Android App

Have you ever tried screen mirroring (or casting) your phone on a Smart Tv? You must have. There are tons of available applications for this task. If you haven’t heard of Screen mirroring, let me explain:

Screen mirroring (sometimes called screen casting) allows you to mirror your mobile device’s content to your TV screen.

It can be used for numerous things including playing games or watching videos on a big screen. It generally has this icon:


Now we will develop our own Android application for this task.

We will use Android Studio for this. If you’re new to Android application development, these can help you get started:

Installing Android Studio

Android Basics by Udacity

So let’s dive into some code!

First, we’ll create a toolbar for our application as generally, this icon lies on the top of the screen. For making a toolbar, let’s start with adding the dependencies to build.gradle (module : app)

compile fileTree(dir: 'libs', include: ['*.jar'])
compile ''

Now in res/layout/activity_main.xml file,  we’ll add the toolbar widget from library :




Now we have to add a menu for the toolbar. In res/menu we’ll add main_menu.xml.

<menu xmlns:android=""

    <item        android:id="@+id/action_fav"



In main_menu.xml, we defined an item to show in the toolbar. The icon used is of screen mirroring same as one above.

After defining the xml elements, now we will head over to the java code to make changes to our MainActivity. Inside java/, initialize the toolbar widget in the onCreate function. For importing any library like in this case, just press Alt + Enter after defining it in the function.

protected void onCreate(Bundle savedInstanceState) {

Toolbar mToolbar = (Toolbar) findViewById(;

After adding the toolbar, we need to inflate the menu bar and handle the click on our screen mirroring icon.

@Override public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(, menu);
return true;

public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == {

startActivity(new Intent("android.settings.CAST_SETTINGS"));
return true;
return super.onOptionsItemSelected(item);

action_fav represents our screen mirroring icon. Inside the onOptionsItemSelected function, we sent an intent to start an activity to “android.settings.CAST_SETTINGS”.

This sends a signal to internal settings to launch the inbuilt screencast services. This service will automatically search a device, make a connection through Wifi-Direct and render your Android device screen on the secondary device. We don’t need to take the pain of going through this whole process ourselves, this little intent will take care of everything!

The application should be working now. Build the project and run.

The results should be like:

You can find the entire application code at:

ScreenMirroring Application

In this post, we developed a simple screen mirroring android application. In the coming post, we’ll develop some more simple daily use Android applications just for fun!

If you have any doubts or queries, post in the comment section.

Thank you!




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s