Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,786,823 Members 42,614 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
QuantumCipher
Old
(Last edited by QuantumCipher; 11th December 2012 at 05:46 PM.)
#1  
QuantumCipher's Avatar
Member - OP
Thanks Meter 55
Posts: 40
Join Date: Jul 2012
Arrow [HOW TO] Make your own Android Toolkit for Windows in C# - Make it to your liking!

[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
The Following 43 Users Say Thank You to QuantumCipher For This Useful Post: [ Click to Expand ]
 
QuantumCipher
Old
#2  
QuantumCipher's Avatar
Member - OP
Thanks Meter 55
Posts: 40
Join Date: 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 5 Users Say Thank You to QuantumCipher For This Useful Post: [ Click to Expand ]
 
Saravanashines
Old
#3  
Member
Thanks Meter 10
Posts: 30
Join Date: Jun 2012
Location: Coimbatore
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: [ Click to Expand ]
 
regaw_leinad
Old
#4  
regaw_leinad's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 3,629
Posts: 3,662
Join Date: Jan 2010
Location: Seattle, WA
Also, you could show them how to integrate my AndroidLib .NET library into it to handle all of the adb stuff
Device: HTC One (AT&T)
Recovery:TWRP 2.6.3.0 | Bootloader: S-OFF
ROM: Stock



My Development Threads

Watch my programming tutorials on YouTube - BetterCoder
I'm also a professional musician - YouTube - SoundCloud


Please don't post just to say "Thanks" - There's a button for that . Be sure to use it!
The Following 5 Users Say Thank You to regaw_leinad For This Useful Post: [ Click to Expand ]
 
jonahly
Old
(Last edited by jonahly; 4th June 2013 at 04:15 AM.)
#5  
jonahly's Avatar
Senior Member
Thanks Meter 130
Posts: 635
Join Date: Oct 2012
Location: Ashland
Nice!! Reserved below Also!! I don't have experience with C# but I can learn by mistakes!
Devices
Sprint LG Optimus G
ROM: Blue Lightning
Kernel: 1.7Ghz
Lenovo ThinkPad A1000
Soft-Bricked.
 
Miniqpa
Old
#6  
Miniqpa's Avatar
Senior Member
Thanks Meter 9
Posts: 142
Join Date: 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
 
menglim
Old
#7  
Senior Member
Thanks Meter 12
Posts: 134
Join Date: Jan 2011

 
DONATE TO ME
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
 
OmarBizreh
Old
(Last edited by OmarBizreh; 4th June 2013 at 03:57 PM.)
#8  
OmarBizreh's Avatar
Recognized Developer
Thanks Meter 3,327
Posts: 1,953
Join Date: Oct 2011
Location: Damascus

 
DONATE TO ME
Quote:
Originally Posted by regaw_leinad View Post
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
The Following 4 Users Say Thank You to OmarBizreh For This Useful Post: [ Click to Expand ]
 
menglim
Old
#9  
Senior Member
Thanks Meter 12
Posts: 134
Join Date: Jan 2011

 
DONATE TO ME
Quote:
Originally Posted by DeepUnknown View Post
+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
 
squabbi
Old
#10  
squabbi's Avatar
Senior Member
Thanks Meter 871
Posts: 1,044
Join Date: Jul 2012
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by DeepUnknown View Post
+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: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes