Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[HOW TO] Make your own Android Toolkit for Windows in C# - Make it to your liking!

OP QuantumCipher

11th December 2012, 06:39 PM   |  #1  
QuantumCipher's Avatar
OP Member
Thanks Meter: 58
 
40 posts
Join Date:Joined: Jul 2012
[HOW TO] Make your own Android Toolkit for Windows using C#

In this tutorial it will show you how to use Windows C# to create your very own toolkit for use of simple ADB commands.

Such as:

- Rebooting your Device.
- Rebooting to Recovery/CWM or Bootloader.
- Installing APK's directly to your device.
- Installing general files to the SDCARD
- Pushing and Pulling files


Or if you look into it enough you can Implement such features as:

- Rooting your Device.
- Unlocking/Locking Bootloader.
- File Permissions.

( These won't Be covered in this Tutorial, as they require much more time, especially Rooting. )

Knowledge required


- A set up Visual C# Studio ready to use on your PC. It can be downloaded here : http://www.microsoft.com/visualstudio/eng/downloads
- General knowledge about C# such as using buttons, text boxes and the actual studio.


Getting Started


So once you have set up your Visual C# studio, create a windows Form application and mess around with the user interface a little if you like to make it to your taste.

So here is a picture of my preview:

I have applied a few different ADB tasks buttons as you can see, Including APK install using a Textbox to store your chose directory of the selected file.( As well as a few colour and form name changes to make it more appealing )




Writing the ADB commands to the chosen Buttons in your application.


Now we want to click on the ADB reboot button until it changes to the code layout as such...



Now we have this layout we want to add the namespaces :

using System.IO;
using System.Diagnostics;


These will allow use for CMD and Process features.

Adding ADB commands to the Buttons


How you have your ADB reboot button code ready to write to.

Use this function: and insert it in between the two Curly brackets
{
var process = Process.Start("CMD.exe", "/c adb reboot");
process.WaitForExit();

}

[/B]

Such as:

MessageBox.Show("Device is Now Rebooting..");

The line uses CMD.exe as the process which will run it as an application and use the /c (command) to execute "adb reboot".

Which will reboot the connected device as long as it's android..

So once you have gone through using the correct ADB commands your application code will look like this..


The ADB wont work yet when running a debug version, so don't try and execute any commands yet.. The adb.exe and a couple of other files need to be stored in the same folder as your toolkit as a resource for ADB to run off of.


Using Textboxes and OpenFileDialog to Install .APK files.


So once you have clicked the two buttons and textbox.



Setting you up ready to code it will look like this:



ADDING CODE


Assuming you have added OpenFileDialog to your Form Design!

We can now add code to the 2 buttons and text box.

It will look like this after adding the following to segments of code.



Add this to Open APK button:

openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Select your APK..";
openFileDialog1.FileName = "Choose File..";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.Filter = " .APK|*.apk";

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{

textBox1.Text = openFileDialog1.FileName;


}

And add this to Install APK file button:

var process = Process.Start("CMD.exe", "/c adb install " + textBox1.Text);
process.WaitForExit();
MessageBox.Show(".APK is Installed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

Now' that is almost it!

Once you have saved and Built a release version of the tool.
Put the .exe from release of the saved directory into a folder ALONG with ADB.exe, ADBWinAPI.DLL and ADBWINUSBAPI.DLL


These ADB files a part of the Android platform tools from the SDK manager. You should already have these if you want to do this process
- If not just google them or download the SDK manager and find them.




Now That's it!


I think I have covered most parts if you want to write your own processes for ADB to execute feel free to do so..

I thought it maybe nice for people who liking personalizing their devices to also personalize toolkits for themselves also!

Thanks and Enjoy if you have any Issues or problems feel free to ask!



Enjoy, QuantumCipher


You can keep upto date on anything I'm doing via Facebook http://www.facebook.com/Quantumcipher

or Youtube https://www.youtube.com/user/QuantumCipher
Last edited by QuantumCipher; 11th December 2012 at 06:46 PM.
The Following 45 Users Say Thank You to QuantumCipher For This Useful Post: [ View ]
12th December 2012, 06:01 PM   |  #2  
QuantumCipher's Avatar
OP Member
Thanks Meter: 58
 
40 posts
Join Date:Joined: Jul 2012
Thanks for the feedback everyone (Y) ....

Not sure if everyone has no idea what C# is or Just like using developer stuff..
The Following 6 Users Say Thank You to QuantumCipher For This Useful Post: [ View ]
1st June 2013, 08:56 PM   |  #3  
Member
Flag Coimbatore
Thanks Meter: 10
 
31 posts
Join Date:Joined: Jun 2012
More
Thumbs up Thanks....
Thanks Man.. i was looking for the same... Can you give me tutorials for rooting and other aspects... Im wating for you....
The Following User Says Thank You to Saravanashines For This Useful Post: [ View ]
4th June 2013, 12:11 AM   |  #4  
regaw_leinad's Avatar
Recognized Contributor / Recognized Developer
Flag Seattle, WA
Thanks Meter: 3,665
 
3,665 posts
Join Date:Joined: Jan 2010
More
Also, you could show them how to integrate my AndroidLib .NET library into it to handle all of the adb stuff
The Following 6 Users Say Thank You to regaw_leinad For This Useful Post: [ View ]
4th June 2013, 05:11 AM   |  #5  
jonahly's Avatar
Senior Member
Flag Ashland
Thanks Meter: 131
 
636 posts
Join Date:Joined: Oct 2012
More
Nice!! Reserved below Also!! I don't have experience with C# but I can learn by mistakes!
Last edited by jonahly; 4th June 2013 at 05:15 AM.
The Following User Says Thank You to jonahly For This Useful Post: [ View ]
4th June 2013, 08:56 AM   |  #6  
Miniqpa's Avatar
Senior Member
Thanks Meter: 11
 
145 posts
Join Date:Joined: Feb 2012
Very nice tutorial!
As long it is a nexus device the rooting and flash cwm thing is the same thing except you're using fastboot commands.


kind regards
The Following User Says Thank You to Miniqpa For This Useful Post: [ View ]
4th June 2013, 09:29 AM   |  #7  
Senior Member
Thanks Meter: 15
 
137 posts
Join Date:Joined: Jan 2011
Donate to Me
More
How can I get output text from cmd.exe? For example, if I have another textbox, and I want to display text. Text can be
Waiting for device ......(in case device not found)
Adb server start......depend on cmd.exe output.

Sent from my Spirit S using xda premium
4th June 2013, 04:46 PM   |  #8  
OmarBizreh's Avatar
Recognized Developer
Flag Damascus
Thanks Meter: 3,364
 
1,981 posts
Join Date:Joined: Oct 2011
Donate to Me
More
Quote:
Originally Posted by regaw_leinad

Also, you could show them how to integrate my AndroidLib .NET library into it to handle all of the adb stuff

+1 on that, it's the shortest way and it was the reason behind Droid Manger existence, thus this tutorial shows what goes inside your lib and it's useful for those who are learning C# for the first time, or never interacted with a process in their app

OP keep up the good work

@menglim:
To get out put from a process, here is an example:
Code:
Process process = new System.Diagnostics.Process();
                        ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                        startInfo.RedirectStandardInput = true;
                        startInfo.RedirectStandardOutput = true;
                        startInfo.RedirectStandardError = true;
                        startInfo.UseShellExecute = false;
                        startInfo.FileName = "cmd.exe";
                        process = Process.Start(startInfo);
                        process.StandardInput.WriteLine(Command_You_Want_To_Give_To_Your_Process);
                        outputTextBox.Text = process.StandardOutput.ReadToEnd();
Hope this helps
Last edited by OmarBizreh; 4th June 2013 at 04:57 PM.
The Following 4 Users Say Thank You to OmarBizreh For This Useful Post: [ View ]
5th June 2013, 12:00 PM   |  #9  
Senior Member
Thanks Meter: 15
 
137 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Quote:
Originally Posted by DeepUnknown

+1 on that, it's the shortest way and it was the reason behind Droid Manger existence, thus this tutorial shows what goes inside your lib and it's useful for those who are learning C# for the first time, or never interacted with a process in their app

OP keep up the good work

@menglim:
To get out put from a process, here is an example:

Code:
Process process = new System.Diagnostics.Process();
                        ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                        startInfo.RedirectStandardInput = true;
                        startInfo.RedirectStandardOutput = true;
                        startInfo.RedirectStandardError = true;
                        startInfo.UseShellExecute = false;
                        startInfo.FileName = "cmd.exe";
                        process = Process.Start(startInfo);
                        process.StandardInput.WriteLine(Command_You_Want_To_Give_To_Your_Process);
                        outputTextBox.Text = process.StandardOutput.ReadToEnd();
Hope this helps

yes, it works but there is cmd.exe window pop up....after I close this window, then I can get the output. it is not in real time...thanks
5th June 2013, 12:04 PM   |  #10  
squabbi's Avatar
Senior Member
Flag Sydney
Thanks Meter: 940
 
1,134 posts
Join Date:Joined: Jul 2012
Donate to Me
More
Quote:
Originally Posted by DeepUnknown

+1 on that, it's the shortest way and it was the reason behind Droid Manger existence, thus this tutorial shows what goes inside your lib and it's useful for those who are learning C# for the first time, or never interacted with a process in their app

OP keep up the good work

@menglim:
To get out put from a process, here is an example:

Code:
Process process = new System.Diagnostics.Process();
                        ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                        startInfo.RedirectStandardInput = true;
                        startInfo.RedirectStandardOutput = true;
                        startInfo.RedirectStandardError = true;
                        startInfo.UseShellExecute = false;
                        startInfo.FileName = "cmd.exe";
                        process = Process.Start(startInfo);
                        process.StandardInput.WriteLine(Command_You_Want_To_Give_To_Your_Process);
                        outputTextBox.Text = process.StandardOutput.ReadToEnd();
Hope this helps

Thanks for sharing this code!

Is it possible for the output to show as it appears on cmd?

Thanks

The Following User Says Thank You to squabbi For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes