How to Make an Android App Using Visual Studio (2024)

Introduction: How to Make an Android App Using Visual Studio

In this Instructables we will be learning how to prepare and run example code on an Android phone using Visual Studio. I used a Samsung Galaxy S20, but this code will work on any Android device. We will be creating an app that turns your flashlight on by the press of a button. By the end of this Instructable you will become familiar with using the Visual Studio IDE. As well as some basic Android programming methods, such as creating elements, controlling hardware, and working with packages. These topics will teach you the basics of app development so that you can go on and learn more advanced programming topics.

Supplies

  • Android Phone
  • Windows Computer
  • Internet Access
  • USB cable to connect your Android phone to your computer

Step 1: Download Visual Studio

Go to the Visual Studio page here and select the Download Visual Studio button. The download should start shortly after. Select somewhere on your computer to save the download, I recommend saving to your desktop.

Step 2: Set-Up Visual Studio

Run the download file, it should be called vs_community__927645998.1618848418.

After running the download file, a window should pop up called "Visual Studio Installer". Select the Continue button.

A new window should appear asking you to select different workloads to download. Select the Mobile development with .NET and Mobile development with C++. After selecting these press the Install button. This process may take several minutes to download and install.

Step 3: Download Visual Studio Extensions

After the workspaces have downloaded, Visual Studio should have started. If not, press the windows button + s and search for Visual Studio and run it.

Select the Continue without code option underneath "Create a new project". A new window should load with a tool bar spanning the top of the windows. Follow these steps to install the needed extensions:

  1. Select the Extensions tool bar at the top of the window
  2. Select the option to Manage Extensions
  3. Search for the extension called Java Tools for Android Project (Visual Studio 2019)
  4. Select the download button next to the extension
  5. Close out of the extensions window
  6. Close out of the Visual Studio window
  7. You should be prompted with a windows called VSIX Installer, select the Modify button
  8. After a few seconds a new windows should appear saying "Modifications Complete", close out of that window

Step 4: Set-Up Your Android Phone

These steps are DIFFERENT depending on the phone you are using. Here is a link to the different ways to do so on different Android Versions.

These are the instructions I followed for my Samsung Galaxy S20.

First, you need to enable Developer Options on your phone.

  1. Go into the Settings menu
  2. Select the button called "About phone"
  3. Select the button called "Software information"
  4. Select the button called "Build Number" 7 times in a row

Now that Developer Options are enabled we need to enable USB debugging on your device.

  1. In the Settings menu select the new option "Developer Options"
  2. Enable the option called "USB debugging"
  3. A prompt should appear called "Allow USB debugging?", select OK

Now we need to connect our phone to the computer using a USB cable. If your computer doesn't already have the Android USB Driver for Windows installed, you can install it here.

Step 5: Create a Test Project

Reopen Visual Studio by pressing the windows button + s and searching for Visual Studio and run it.

Select the option called Create a new project under "Get started". It will ask you for what kind of application you would like to create.

  1. Under the All platforms tab select Android
  2. Under the All project types tab select Mobile
  3. Select the Android App (Xamarin) option and press the next button.
  4. You should be sent to a page wanting you to enter a project name, name it TestAndroidApplication.
  5. Select the check box next to Place solution and project in the same directory.
  6. Press create when done.

Now you should be prompted with what kind of template you want to use, in this example I used Single View App and selected the Android Version 9.0(Pie). The version may differ depending on what Android version you are using. Press OK when done.

Step 6: Run the Test Application

Now you should be sent to a new window with lots of code on it. Ignore the daunting looking code, all we want to do is run the code. Press the green arrow button at the top of the screen to run the code. It should have the name of the android device you are using next to it. If you don't see this. Unplug your android device from your computer and plug it back in. Once you pressed the green arrow to run the app. Wait a few seconds for it to compile. You should see a simple app running on your phone that says "Hello world".

Step 7: Create a Blank App Project

First you will need to close out of Visual Studio, then reopen it so you are sent back to the home menu. Now select the option called Create a new project under "Get started". It will ask you for what kind of application you would like to create. Under the All platforms tab select Android, and under the All project types tab select Mobile. Select the Basic Application (Android, Ant) option and press the next button. You should be sent to a page instructing you to enter a project name, name it FlashlightApp. Also make sure that Place solution and project in the same directory is selected. Press the create button when done.

Step 8: Import the Needed Packages

Now the file called FlashlightApp.java should show up on the main window. If not, you can find it in the Solution Explorer at FlashlightApp->src->com->FlashlightApp->FlashlightApp.java.

Now we need to import the write packages to get the code we use later on to work. Add the code below:

ADD THIS CODE

import android.view.View;import android.widget.Button;import android.graphics.Color;import android.hardware.camera2.CameraAccessException;import android.hardware.camera2.CameraManager;<br>

UNDERNEATH THIS CODE

import android.os.Bundle;

Step 9: Creating a Button

Now we need to delete some of the default code that's was created with the project with code that will create a button.

DELETE THIS CODE

/* Create a TextView and set its text to "Hello world" */TextView tv = new TextView(this);tv.setText("Hello World!");setContentView(tv);<br>

ADD THIS CODE

// This portion of code creates the button and sets its propertiesButton button = new Button(this); // Creates a buttonbutton.setBackgroundColor(Color.BLACK); // Sets background colorbutton.setTextColor(Color.GRAY); // Sets text colorbutton.setText("Flashlight"); // Sets text to "Flashlight"setContentView(button); // Sets button size to 

Step 10: Add Button Logic

Now we need to create the method for what the button should do when pressed. Add this code below the code we entered for creating the button.

ADD THIS CODE UNDER THE BUTTON CODE

 // This portion of code if the logic of the button press button.setOnClickListener(new View.OnClickListener() // Checks for when any button is clicked { int i = 2;// Used for button logic public void onClick(View button) // Checks for when the button called "button" is clicked { if(i%2 == 0) // When button is pressed { button.setBackgroundColor(Color.BLACK); // Sets background color to black i++; // This portion of code is for setting the camera on try { cameraManager.setTorchMode(getCameraID, false); // Sets flashlight off } catch (CameraAccessException e) { e.printStackTrace(); } } else // When button is pressed again { button.setBackgroundColor(Color.WHITE); // Sets background color to white i++; // This portion of code is for seting the camera on try { cameraManager.setTorchMode(getCameraID, true); // Sets flashlight on } catch (CameraAccessException e) { e.printStackTrace(); } } } });<br>

Step 11: Add a Flashlight Controller

Now we need to add the code to get the flashlight to work.

ADD THIS CODE UNDER THE CLASS

private CameraManager cameraManager;private String getCameraID;<br>

ADD THIS CODE UNDER THE BUTTON CODE

// This portion of code initializes the flashlight on your device and then gets the IDcameraManager = (CameraManager) getSystemService(Android1.CAMERA_SERVICE);try {getCameraID = cameraManager.getCameraIdList()[0];} catch (CameraAccessException e) {e.printStackTrace();}<br>

Step 12: Compile and Run the Code

Press the green arrow button at the top of the screen to run the code. It should have the name of the android device you are using next to it. If you don't see this. Unplug your android device from your computer and plug it back in. Once you pressed the green arrow to run the app. Wait a few seconds for it to compile. You should see an app called FlashlightApp running on your phone.

Step 13: Test Out the App

Press the button called Flashlight. Then color of the button should change to white, and the flashlight on your phone should turn on. Pressing the button again should change the button color back to black and the flashlight off.

Congratulations, you just created your first Android app!

Be the First to Share

    Recommendations

    Build a UV Level Monitoring Budgie - Using IoT and Weather Data APIs by Hey Jude in Arduino

    28 2.0K

    DIY Weather Station With ESP32 by Giovanni Aggiustatutto in Electronics

    558 46K

    Automated 35mm Slide Digitizer by rbwood53 in Arduino

    123 12K

    Life Sized Talking BMO From Adventure Time (that's Also an Octoprint Server!) by katzcreates in 3D Printing

    87 7.5K

    • Plywood Contest

    • Back to School: Student Design Challenge

    • CNC and 3D Printing Contest

    2 Comments

    tytower

    1 year ago

    Can you post the complete code as a text file please (or in any editor type file). That way it can be used by many other coding programs without trying to piece together your code and picking up garbage with copy and paste.
    I use Linux so I have Visual Studio Code.

    Its good that you share this as its a very useful technique. Thanks.

    Penolopy Bulnick

    1 year ago

    Thanks for sharing :)

    How to Make an Android App Using Visual Studio (2024)

    FAQs

    Can I create Android app in Visual Studio? ›

    Build Android apps with Azure App Service Mobile Apps. Work with data in the cloud or on-premises. Sync data for offline use, authenticate users, and send personalized push notifications from a secure and scalable mobile app backend. Create a new app or connect an existing project—all in Visual Studio.

    Can you make a mobile app with Visual Studio? ›

    You can build apps for Android, iOS, and Windows devices by using Visual Studio. As you design your app, use tools in Visual Studio to easily add connected services such as Microsoft 365, Azure App Service, and Application Insights.

    How do I use Visual Studio to make an app? ›

    Build your Android app in the cloud with Visual Studio App Center
    1. Sign up with App Center at appcenter.ms. App Center Login.
    2. Create a new app. Select “Add new” button -> Add new app. ...
    3. Configure your repository. ...
    4. Configure your Build & Distribute. ...
    5. Install your app.
    16 Oct 2020

    Can I make an app with Visual Studio code? ›

    Download and install Visual Studio Code. Install extensions for basic web development. Use the basic editor functionality of Visual Studio Code. Write and test a simple web app.

    Is C# good for mobile apps? ›

    These will be Native mobile apps and will be compatible across various platforms such as Android, iOS and Windows. Also, C# has a cleaner and simpler syntax than Java, making it relatively easy to code. So for beginners, it might be a better choice than Java.

    Can we make Android app using C#? ›

    MonoDroid is a framework that is used to build Android-based mobile applications using C# and . NET. In this tutorial, we learned how to get started with the MonoDroid framework and Android SDK and build and deploy a simple Android-based application.

    Which is better Android Studio or Visual Studio? ›

    "Android studio is a great tool, getting better and bet " is the primary reason why developers consider Android Studio over the competitors, whereas "Intellisense, ui" was stated as the key factor in picking Visual Studio.

    What language are Android apps written? ›

    1. What language are Android apps written in? The majority of Android apps are written in Java and Kotlin. In some cases, programming languages like C, C++, and Basic are also used.

    Is there a Visual Studio code for Android? ›

    Visual Studio Code is not available for Android but there are some alternatives with similar functionality. The best Android alternative is Neovim, which is both free and Open Source.

    How do you create a mobile app? ›

    How to create an app for mobile devices
    1. Get your app idea on paper.
    2. Build a Native app or a PWA, based on your needs.
    3. Make your app using the right method for your business.
    4. Create an app with an app builder (no-code option)
    5. Test your app on iOS and Android devices.
    6. Submit and Publish your app on the stores.
    1 Jun 2022

    Can I use VS Code instead of Android studio? ›

    Both the IDE are really good. But Android Studio takes more time to open and it also consume more memory than VS Code. If you are beginner then go for Android Studio but after some time you can shift to VS code.

    Can I use Visual Studio for web development? ›

    Visual Studio includes integrated tools to deploy your web application to any host or scale to the Microsoft Azure cloud. Publish and manage your websites and virtual machines from within Visual Studio.

    Is xamarin free? ›

    Free. Cross-platform. Open source. An app platform for building Android and iOS apps with .

    Is learning C# hard? ›

    C# is one of the easiest programming languages to learn. C# is a high-level, general-purpose programming language that is easy to read because of its well-defined class hierarchy. It is the perfect language for beginner developers as it will be straightforward to grasp compared to most other languages.

    Which is the easiest language for app development? ›

    If you plan on creating an Android app, Java could be the way to go. According to a recent survey, JavaScript is the most popular language among developers, with around 69.7 percent using it. HTML/CSS is the second most popular language, with 62.4 percent of respondents saying they code with it.

    What apps are made with C#? ›

    Here are a handful of programs and applications written in C# that demonstrate the language's diversity and reliability:
    • Windows Installer XML.
    • Microsoft Visual Studio.
    • Paint.NET.
    • Open Dental.
    • KeePass.
    • FlashDevelop.
    • Banshee.
    • NMath.
    15 May 2019

    Does Apple use C#? ›

    C# (pronounced “c-sharp”) is a great coding language that works across Mac and PC. Programmers use it to build a variety of software applications, especially in the Windows environment.

    Can we do Android development in VS Code? ›

    Connect an Android phone to your computer and open your folder containing the Android project in VS Code, making sure that is the folder directly containing your "app" folder. Then go to the Run tab, tap on "create a launch.

    Does C# run on iPhone? ›

    Continuous is a fast and powerful . NET C# and F# IDE that runs directly on the iPad and iPhone (no network needed!). With it, you can write apps and games using your favorite languages on your favorite devices.

    › app-center › get-started ›

    Setup a continuous integration and delivery pipeline for Android apps. Connect to any Git repo and have your team up and running in minutes. Try creating your o...
    Building an app for Android? No matter how you're building it, you might be surprised by what Microsoft offers to support you.
    Xamarin Developer Evangelist James Montemagno shows you how the Xamarin Platform enables developers to leverage their C# and .NET skills to create native mobile...

    Which is better Android Studio or Visual Studio? ›

    "Android studio is a great tool, getting better and bet " is the primary reason why developers consider Android Studio over the competitors, whereas "Intellisense, ui" was stated as the key factor in picking Visual Studio.

    Is there a Visual Studio code for Android? ›

    Visual Studio Code is not available for Android but there are some alternatives with similar functionality. The best Android alternative is Neovim, which is both free and Open Source.

    Can I use VS Code instead of Android Studio? ›

    Both the IDE are really good. But Android Studio takes more time to open and it also consume more memory than VS Code. If you are beginner then go for Android Studio but after some time you can shift to VS code.

    What software is used to create apps? ›

    Best-in-class breakdown of app development software
    ProductIndustry Rating*Free Trial
    Microsoft Azure4.30Yes
    Bitbucket4.30Yes
    Kintone5.00Yes
    Google Cloud Platform4.25Yes
    8 more rows
    11 Oct 2022

    Which is better kotlin or Flutter? ›

    Flutter and Kotlin are the two leading technologies used to build mobile applications. Flutter is a framework, while Kotlin is a programing language.
    ...
    Flutter vs. Kotlin.
    ParametersFlutterKotlin
    App SizeThe size of the Flutter app is bigger.The size of the Kotlin app takes less size as compared to Flutter.
    14 more rows

    Why VS Code is better than Android Studio? ›

    Android Studio is a much heavier IDE than VS Code, consuming closer to a solid gigabyte of memory, while VS Code consumes substantially less. It also participates in fairly resource-intensive operations, like indexing your code when you load your project.

    What language are Android apps written? ›

    1. What language are Android apps written in? The majority of Android apps are written in Java and Kotlin. In some cases, programming languages like C, C++, and Basic are also used.

    Is Visual Studio code better than Visual Studio? ›

    If you need to collaborate with team members on development or debugging, then Visual Studio is the better choice. If you need to do serious code analysis or performance profiling, or debug from a snapshot, then Visual Studio Enterprise will help you. VS Code tends to be popular in the data science community.

    Is VS Code an IDE? ›

    Visual Studio Code is a streamlined code editor with support for development operations like debugging, task running, and version control. It aims to provide just the tools a developer needs for a quick code-build-debug cycle and leaves more complex workflows to fuller featured IDEs, such as Visual Studio IDE.

    Can you make Android apps in VS Code? ›

    Yes! Microsoft's Visual Studio Code (derived from the open-source text editor Atom), is the most popular among developers. ... Dave Holoway, a compelling Senior Developer in London, created the extension "Android" to build and debug Android apps using VS Code, once you already have the right Android SDK installed.

    Can you build Android apps without Android Studio? ›

    Yes it is possible to create Android apps without using Android Studio. To make an Android apps is a fantastic idea, if you are a business looking to reach a broader audience, an entrepreneur hoping to make some passive income or simply looking to learn a fantastic new skill.

    What is better Android Studio or Flutter? ›

    Android studio and Gradle both make it easy to run tests on your applications. On the other hand, flutter's testing tools are robust and well-suited for the unit, widget, and testing and integration of mobile apps. So, Android studio is easy as compared to flutter.

    Top Articles
    Latest Posts
    Article information

    Author: Eusebia Nader

    Last Updated:

    Views: 5540

    Rating: 5 / 5 (60 voted)

    Reviews: 83% of readers found this page helpful

    Author information

    Name: Eusebia Nader

    Birthday: 1994-11-11

    Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

    Phone: +2316203969400

    Job: International Farming Consultant

    Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

    Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.