[Android General] Beatsleigher:
Hello guys,

I know there are multiple guides like this one on the forums, but I guessed: Why should one just have tutorials in Batch and C#? I can program in VB, why not share it?

First: This guide will contain some code out of my own program (Universal Android Toolkit) but only the free stuff :p

So, I guess I'll start off.

Prerequisites:​

What will you need?

Microsoft Visual Studio (2008, 2010 or 2012) for Windows Desktop. I'll provide links.

A computer with at least 1GB RAM, a P4 @ 2.8GHz, 128MB Graphics chip/card, some basic knowledge of ADB commands (You'll learn them here, I guess...)

A cup of coffee or whatever your favorite warm beverage is.

Oh, and some decent music would be good.

Setting things up:​

As I've already done this a while back, I cannot provide screenshots, but I'll do my best to explain things.

First, download Visual Studio 2012 for Windows Desktop and open the installer.

It should look somewhat like this, just with a big 'START' button at the bottom.

Once you have installed that, it is advisory, that you download the .Net framework 3.5, 4.0 and 4.5

.Net 3.5 (Includes 2.0, 3.0 and 3.5 SP1

.Net 4.0

.Net 4.5

Once you have installed those, you should bookmark this page and restart your computer.

Then, move to the next step.

Creating a New Project:​

Open up Visual Studio. You will be welcomed by a screen, which looks somewhat like this:

Click on 'New Project...'

You will then see this type of screen:

Select 'Windows Forms Application' and give it a name. You may name it whatever you want. You can also change the location it should be stored in. I'll change the name to Android One-Click Tutorial and I'll leave the default location as it is.

Once you have done that, hit OK and wait for the project to load up.

One-Click, Here we Come!:​

Once the project has loaded, you will see a screen like this (Depending on which version of VS you are using..)

You may name the form however you want. I'll name it the same as the project.

Once you have given it a name, you'll want to resize the form to the desired size and give it an icon.

Please excuse the weird highlights, I'm using my old laptop, because my computer broke and my mouse died with it.

Then debug the program, to make sure it is how you want it to be.

If it's OK for you, then let's get to downloading all the ADB-Stuff.

Download the ADT bundle from here and then download the platform-tools.

You might want another cup of coffee for this. Sadly, I can't drink anything warm or with caffeine, because I had an operation to my mouth yesterday (Friday the 07th of June 2013) so feel free to drink one on me :D

Once it is done downloading, extract the archive to your computer. I'll just put it in my Documents folder.

Once everything is extracted, move to the sdk\platform-tools folder. Make sure that the files 'adb.exe', 'AdbWinApi.dll', 'AdbWinUsbApi.dll' and 'fastboot.exe' are present. If they are, go back to Visual Studio and go to the properties of the project (Project ->> <Project Name> properties) and move to 'Resources'. Change the resource type from Strings to Files.

Then, add the four files from above to the resources.

Once all that is done, we can start coding.

So go ahead and double-click on the form, so that the code file shows up.

It'll look like this:

Type in the following over Public Class Form1:

Imports System.IO
Imports System.Threading
Imports System.Windows.Forms.DialogResult

Now, as this program is supposedly going to be used by others, probably people without knowledge of coding, and therefore people without ADB, etc., we want the program to look for our files and copy them if necessary.

We want to do this right at the beginning of the program, so we'll do it the Form1 Load Event.

Type the following code:

If Not Directory.Exists("ADB") Then
Directory.CreateDirectory("ADB")
Else
If Not File.Exists("ADB\adb.exe") Then
File.WriteAllBytes("ADB\adb.exe", My.Resources.adb)
End If
If Not File.Exists("ADB\AdbWinApi.dll") Then
File.WriteAllBytes("ADB\AdbWinApi.dll", My.Resources.AdbWinApi)
End If
If Not File.Exists("ADB\AdbWinUsbApi.dll") Then
File.WriteAllBytes("ADB\AdbWinUsbApi.dll", My.Resources.AdbWinUsbApi)
End If
If Not File.Exists("ADB\fastboot.exe") Then
File.WriteAllBytes("ADB\fastboot.exe", My.Resources.fastboot)
End If
End If

The code folder should now look something like this:

Ok. So now debug the program and check in the project's \bin folder for a folder named ADB and check if all the files were created accordingly.

If your folder looks like mine: You've done a great job! So you can already give yourself a pat on the back!

Now, to move on to the next step:

Adding Buttons and Commands:​

Move back to the designer and add a few buttons like I've done. The buttons I've created will:

Back up the device

Restore the device

Install an app

Push a file

Now, we want to create four more forms. One for the backup, one for the restore, one for the install app and one for pushing a file.

Hit CTRL+SHIFT+A to add new items.

You can name the forms however you want.

I created some with pretty self-explaining names:

Now, double-click on each button in Form1 to create a new code block in the code file.

Once you have done that, copy the following codes into each code block.

Button1_Click

Backup.Show()
Me.Hide()

Button2_Click

Restore.Show()
Me.Hide()

Button3_Click

Install.Show()
Me.Hide()

Button4_Click

Push.Show()
Me.Hide()

Now open up the Backup form. We'll start here. You can close the Form1-files.

Start designing the form as you wish. Here's how I've done it:

If you're using the same design as me, you might want to use the same code.

NOTE: I rarely use the .Net components in the Toolbox. Only for static operations. For things like dialog boxes, I use pure code.

This is working code. I have debugged and tested!

Imports System.IO
Public Class Backup

Private Sub Backup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox2.Text = "Backup_From_" & Date.Now.ToShortTimeString
If Not Directory.Exists(TextBox1.Text) Then
Directory.CreateDirectory(TextBox1.Text)
End If
End Sub

Private Sub Backup_FormClosing(sender As Object, e As EventArgs) Handles MyBase.FormClosing
Form1.Show()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FolderBrowse As New FolderBrowserDialog
FolderBrowse.Description = "Select the destination of where you wish your backup to be saved to." _
& "Note: Please do not choose locations with spaces in the directories. These may cause errors!"
FolderBrowse.ShowNewFolderButton = True
Dim DialogRes As DialogResult = FolderBrowse.ShowDialog
If DialogRes = Windows.Forms.DialogResult.OK Then
TextBox1.Text = FolderBrowse.SelectedPath
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Shell("""ADB\adb.exe"" backup -f" & TextBox1.Text & "\" & TextBox2.Text & "-apk -system -full -all", AppWinStyle.NormalFocus, True, 30000)
End Sub
End Class

Once you have that done, move to the next form. This, in my case, is Restore.

To keep the thread clear, I'll carry on in post #2.