[DEV] AndroidLib - .NET Android Device Communication and Management Library 01.20.13

Search This thread

_Logie

Senior Member
Jan 24, 2012
85
174
Absolutely fantastic development mate. Really really good work you've done there.

If I ever jump back to C# for an Android app I will most definitely incorporate your library.
 
  • Like
Reactions: regaw_leinad

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Updated to v1.0.0.1, minor nightly bug fix. Stay tuned in for v1.0.1.0. If developing right now with 1.0.0.0, you should update the dll right away, due to some issues with certain phones and how I coded the Process class.
 

Strict

Member
Feb 6, 2009
18
9
Almada
Nice, I'll going to try it in a few minutes.

Thanks for the update :)

Edit: I'm getting this error - Requested value 'TY' was not found.

Sent from my X10i using Tapatalk
 
Last edited:

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
Hi, this dll is awesome! The options it has are perfect for my Galaxy S Plus Configurator. Very nice development which will help loads of people programming their android related application. The only thing is that I'm not experienced with calling dll's at all, I use AutoIT v3 as programming language, it's a pretty easy language but has a large amount of functions. Luckily it allows you to call dlls, the help reference says this:
Here is a link to the full reference: DllCall()

Code:
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )

Ok so for example, I tried calling the device status (don't laugh at me) with this command:

Code:
$open = DllOpen(@ScriptDir&"\AndroidLib.dll")
DllCall($open, "get", "DeviceState", "get")
ConsoleWrite(@error)

Returns "4", which means: "bad number of parameters"
I know the real developers are laughing at me right now but I have no clue on how to continue that line, I tried allot of things but can't figure it out, is there someone who can tell me how you can call the dll correctly using this syntax?:

Code:
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )

So basically I need to know which "return type" i need to use and how I call a function in the dll correctly.

Thanks in advance, this dll is great! +1 to dev
 
Last edited:

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Hi, this dll is awesome! The options it has are perfect for my Galaxy S Plus Configurator. Very nice development which will help loads of people programming their android related application. The only thing is that I'm not experienced with calling dll's at all, I use AutoIT v3 as programming language, it's a pretty easy language but has a large amount of functions. Luckily it allows you to call dlls, the help reference says this:
Here is a link to the full reference: DllCall()

Code:
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )
Ok so for example, I tried calling the device status (don't laugh at me) with this command:

Code:
$open = DllOpen(@ScriptDir&"\AndroidLib.dll")
DllCall($open, "get", "DeviceState", "get")
ConsoleWrite(@error)
Returns "4", which means: "bad number of parameters"
I know the real developers are laughing at me right now but I have no clue on how to continue that line, I tried allot of things but can't figure it out, is there someone who can tell me how you can call the dll correctly using this syntax?:

Code:
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )
So basically I need to know which "return type" i need to use and how I call a function in the dll correctly.

Thanks in advance, this dll is great! +1 to dev

:( Unfortunately, AutoIt is not able to make calls to .NET dlls. .NET dlls are not compiled the same ways as normal Win32 executables, and don't have an export table for use like this. Even if they did, I'm not sure it would work with AutoIt anyways, because the way I programmed it, the main class AndroidController handles all of the Devices which in turn handles all of the device's information. There are no static methods/properties to call regarding any device data :( Sorry I can't help out with that! BUT, I can show you to this website, which I used years ago when I started learning Visual Basic/C#. Go HERE, and I highly recommend either the Visual Basic .NET for Beginners or C# for Beginners, they cost around $8 for each pdf, but they are both around 450 pages and really do give you exactly what you need to start out, and towards the end get a little more advanced. They are exactly what I used to start with VB and C# back in the day, and are updated now to VS2010. PM me if you want any more help!
 

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
:( Unfortunately, AutoIt is not able to make calls to .NET dlls. .NET dlls are not compiled the same ways as normal Win32 executables, and don't have an export table for use like this. Even if they did, I'm not sure it would work with AutoIt anyways, because the way I programmed it, the main class AndroidController handles all of the Devices which in turn handles all of the device's information. There are no static methods/properties to call regarding any device data :( Sorry I can't help out with that! BUT, I can show you to this website, which I used years ago when I started learning Visual Basic/C#. Go HERE, and I highly recommend either the Visual Basic .NET for Beginners or C# for Beginners, they cost around $8 for each pdf, but they are both around 450 pages and really do give you exactly what you need to start out, and towards the end get a little more advanced. They are exactly what I used to start with VB and C# back in the day, and are updated now to VS2010. PM me if you want any more help!

Oh that's a pity, really wanted to use it with AutoIT. Thanks for the link I will take a look there. I currently have C# lessons at school, so could give it a shot in C# I guess. This could be an option, I think of it like this:

Creating a C# application which includes all functions from the dll, which is available to call it with a parameter, like this:

Run AndroidLib.exe "DeviceStatus"

and in the C# application the parameter that is given (%1) is returning the function, could read it out with STDREAD or so. but still I think this isn't a great solution to be honest.

Thanks anyway, good luck with your awesome dll :D
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Wew!
im also having problem on calling it on dot net :'(

while im still reading driveInfo Class

hope someone here could make it more easy for me to call it


TIA
regrds

What are you trying to do, be more specific. You should not have to use the DriveInfo class to use my dll... Did you read the included "Getting Started.txt"?
 
  • Like
Reactions: EYESTRA1N

EYESTRA1N

Senior Member
Feb 21, 2009
60
6
Bendar Brunei
level5team.com
What are you trying to do, be more specific. You should not have to use the DriveInfo class to use my dll... Did you read the included "Getting Started.txt"?



i just read now,
okey now i understand a lil bit.

i know i can figure this out.
using System;
using RegawMOD.Android;

class Program
{
static void Main(string[] args)
{
Device device;

using (AndroidController android = new AndroidController())
{
Console.WriteLine("Waiting For Device");
android.WaitForDevice(); //This will wait until a device is connected to the computer

device = android.ConnectedDevices[0]; //Sets device to the first Device in the collection

Console.WriteLine("Connected Device - {0}", device.SerialNumber);
}
}
}

anyway thank you so much for this thing
its a big help for us

i really appreciate it
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
i just read now,
okey now i understand a lil bit.

i know i can figure this out.


anyway thank you so much for this thing
its a big help for us

i really appreciate it
Once I finish updating this and a rebuild of my HTC Hero Rooter using this library, I will write a sample windows forms application using AndroidLib, and give out the source of that sample project, so you can see how I would do it.
 

drcell

Senior Member
Apr 22, 2008
59
16
May i get an example about getting connected device like "adb devices" in Visual Basic 2010? For example when i click a button, connected device's serial no can appear in the text box. If no device connected an error appear in the same text box.

I am not an expert but i need a small app for connecting to android device and getting if its connected.

Thanks...
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
May i get an example about getting connected device like "adb devices" in Visual Basic 2010? For example when i click a button, connected device's serial no can appear in the text box. If no device connected an error appear in the same text box.

I am not an expert but i need a small app for connecting to android device and getting if its connected.

Thanks...

See post #2 in this thread. I added a post of sample Visual Studio solutions so you can see how to use AndroidLib the way I intended it to be used. More to come as I update them
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Also, if you use this and/or find it useful to anyone, PLEASE hit the "Submit Thread as News Tip" button at the top of the thread! That might get this library on the front page of xda, which in turn lets many more developers see it!
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Sorry man,

1.0.0.2 wont recognize any phone..... :D


And...is it possible to manage the phone through a Bluetooth connection? Would be really cool! :D

Recognizes all fine for me, what exactly do you mean? When you call android.ConnectedDevices, it's always empty? check android.HasConnectedDevices, that'll tell you if there are any connected.
 

Mrc527

Senior Member
Mar 28, 2011
171
94
Milan
www.kernel-xp.net
Yep.

This simply tells me every time "No phone connected". And in "android.ConnectedDevice" there is nothing.

Code:
Device device;
            AndroidController android = new AndroidController();
            if (android.ConnectedDevices.Count < 1)
            {
                MessageBox.Show("No phone detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (android.ConnectedDevices.Count > 1)
            {
                //TODO: Select phone
            }

            device = android.ConnectedDevices[0]; 

            Console.WriteLine("Connected Device - {0}", device.SerialNumber);
            Adb.ExecuteAdbCommandNoReturn(android, Adb.FormAdbCommand("forward tcp:" + adb_port + " tcp:" + adb_port, ""));

using the same code with the 1.0.0.1 release is working.

I'm testing with a Galaxy Nexus, a Desire Z and an LG Optimus One.
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
Yep.
This simply tells me every time "No phone connected". And in "android.ConnectedDevice" there is nothing.
using the same code with the 1.0.0.1 release is working.
I'm testing with a Galaxy Nexus, a Desire Z and an LG Optimus One.

Ah, I need to improve the UpdateDevices method in my dll, I'm working on that today actually, instead of a call, I'm going to have it on a constant loop with events for device added/removed/state change. I'm hoping to release it today. for the mean time, here is a modification to your code that will work. I tested it.
Code:
Device device;
            AndroidController android = new AndroidController();

            while (!android.HasConnectedDevices) {}

            device = android.ConnectedDevices[0];

            Console.WriteLine("Connected Device - {0}", device.SerialNumber);

            Console.ReadLine();
            Adb.ExecuteAdbCommandNoReturn(android, Adb.FormAdbCommand("forward tcp:" + adb_port + " tcp:" + adb_port, ""))
try and use the .HasConnectedDevices boolean for checking if there are any devices plugged in. It's a shortcut I made for the ConnectedDevices.Count checking and cleans up the code look a bit. but here in the example, I just put that check on a loop, it only loops for about 320 milliseconds in the test I made. I'll work on fixing all of that though today.

And also, the Adb class has a method PortForward that does the same thing as you wrote in the last line, just
Code:
Adb.PortForward(android, device, adb_port, adb_port);
no need to run Adb.Execute.... on it.
 

regaw_leinad

Inactive Recognized Developer
Jan 30, 2010
3,667
3,787
Seattle, WA
www.regawmod.com
I understand there are issues with this new release. I have been having trouble figuring out a new solution to this problem. I will keep thinking about solutions. For now, 1.0.0.1 is the best one to use. It is not multithreaded however, and may freeze your WinForms app for a little bit while it updates the device list.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 102
    Description:
    AndroidLib is a .NET assembly written in C# (C-Sharp) that easily handles communication between a connected Android device and your program. Currently, there is a large amount of automated controls, eliminating thousands of lines of code the programmer has to write themselves. The class AndroidController is a semi-wrapper of the ADB (Android Debug Bridge) binary. The other class you will be working with the most is the Device class. This class contains useful information about the device (for example: software/hardware info, memory info, battery stats, mount points for partitions, root status, busybox information, and much more), as well as exposes many instance methods to control your phone such as Rebooting, Mounting Filesystems, Push/Pull/Install Files, and much more to come. AndroidLib contains all of the Android binaries necessary to work properly. AndroidLib also assumes that the phone's USB drivers are already installed correctly on the target machine, or that your program will take care of it on it's own.

    This is perfect for any developer who would like to create, for example, an auto-rooter or any other application that needs to connect with Android devices through a .NET application. AndroidLib provides all the methods needed to communicate with the Android device. This will cut back on the code you have to come up with and write yourself by a HUGE amount!

    What it does:
    • Provides easy-to-use code for communicating with Android devices in .NET
    • Provides easy access to information about the connected Android devices
    • Has a large list (and growing...!) of methods that control connected Android devices
    Please credit the work here by me in your own projects; not only to give thanks to me and the many hours I am putting in to this project, but so others know where to find it if they need to!


    Usage:
    Add a reference to AndroidLib.dll in your .NET project and begin using this great API. Please refer to the "Getting Started.txt" guide and full documentation included in the zip.

    Requirements:
    .NET 3.5 or Higher

    Changelog (Only most recent version displayed, full Changelog in download)
    Version 1.5.1.0 | 01.21.13
    • Fixed Device.InstallApk() bug

    Download Latest Release
    GitHub
    Online Documentation

    Sample Solutions Using AndroidLib:
    C# (C Sharp)
    Visual Basic (VB)
    14
    AndroidLib Featured Projects by XDA Users:

    • RegawMOD Evo 4G LTE Rooter - XDA
    • RegawMOD CDMA Hero Rooter - XDA
    • RegawMOD Rebooter - XDA
    • Droid Manager by DeepUnknown - XDA - Google
    • Android SMS - XDA - Home Page
    • Quick ADB Pusher by Goatshocker - XDA
    6
    reserved just in case ;)
    4
    Updated AndroidLib to 1.5.0.0 :D

    • Added Device.FastbootReboot()
    • Added Device.PushFile()
    • Fixed All Reboot Bugs
    • Added Locking for better thread safety
    • Removed unneeded dependencies
    3
    It would be great!
    Can you add something like adb forward? So we can connect to an android service without using ADB, that as we all know sucks!:D
    Yeah, I'll throw in a method to create a port forward. What I have now uses the bridge, which is included in the assembly, but handles all of it silently and very well. I should have a build out soon (most likely this weekend). As long as you don't dispose the AndroidController object, that port forward will be good, so you can use your own Socket code