Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Does XE8 C++, have an equivalent class like native WiFi Manager (ANDROID)


This question is answered.


Permlink Replies: 5 - Last Post: Jun 16, 2015 5:55 PM Last Post By: Anupama Annambh...
Anupama Annambh...

Posts: 24
Registered: 1/16/15
Does XE8 C++, have an equivalent class like native WiFi Manager (ANDROID)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2015 11:52 AM
Is there any means to Get the WiFi status of the Android target device?
If so which Class of Embarcadero's XE8 C++ builder supports this?

I have googled several articles, but ended up always redirected to native code for Android that too in Java.
Can anyone please point me to the Class that supports calls like

- GetWifiStatus()
- SetWifiStatus to True/ False
etc?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Does XE8 C++, have an equivalent class like native WiFi Manager(ANDROID)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2015 8:22 PM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama wrote:

Is there any means to Get the WiFi status of the Android target
device?

Of couse - via Android's own WifiManager class.

If so which Class of Embarcadero's XE8 C++ builder supports this?

None. You have to access Android's native classes directly, using FireMonkey's
Android bridge framework.

I have googled several articles, but ended up always redirected
to native code for Android that too in Java.

Because that is how Android APIs are implemented and accessed - as Java-based
APIs. Which is why FireMonkey provides a bridge framework so Delphi/C++
code can make calls into those Java APIs.

--
Remy Lebeau (TeamB)
Anupama Annambh...

Posts: 24
Registered: 1/16/15
Re: Does XE8 C++, have an equivalent class like native WiFi Manager(ANDROID)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2015 9:32 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you very much Remy Lebeau.

I appreciate any further insight you may be able to provide on this.

Approach#1. Use the Built In RAD Studio Java Libraries for Android

http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_the_Built-in_RAD_Studio_Java_Libraries_for_Android

The RAD Studio Installation Folder has the Androidapi.JNI.Net.HPP file.
And I see the isWifiEnable() method in it.

I guess I am missing the piece which makes RAD Studio find the Reference to Wifimanager class here.
Please help!

Here is the code snippet. I am getting undefined identifier Wifimanager error during compile time.

#include <Androidapi.JNI.Net.HPP>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int wifistate;
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifistate = wm.isWifiEnabled();
Label1->Text = wifistate;

}

Approach#2.

The Embarcadero's Wiki article here http://docwiki.embarcadero.com/RADStudio/XE8/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android , talks about generating DELPHI native bridge files from JAR libraries. I am not sure if the Java2OP.exe is what I need to use for C++ or is there any other tool for it?

Example in that page:
Exporting some classes and packages from the Android API:
Java2OP.exe -classes android.net.ConnectivityManager android.location.*

I am not sure what would be the next steps for this approach :-(

Edited by: Anupama Annambhatla on Jun 16, 2015 3:31 PM

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Does XE8 C++, have an equivalent class like native WiFiManager(ANDROID)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2015 5:12 PM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama wrote:

The RAD Studio Installation Folder has the Androidapi.JNI.Net.HPP
file. And I see the isWifiEnable() method in it.

It is a method of RADStudio's JWifiManager interface, yes. Which is the
interface used to access Android's WifiManager class (the J in Delphi's interface
stands for Java).

In Java, WifiManager.isWifiEnable() is retreived like this:

WifiManager WifiMgr = (WifiManager) Context.getSystemService(Context.WIFI_SERVICE);
boolean WifiIsEnabled = WifiMgr.isWifiEnabled();
...


The equivilent in Delphi is:

uses
  Androidapi.Helpers,
  Androidapi.JNI.Net;
 
var
  obj: JObject;
  WifiMgr: JWifiManager;
  WifiIsEnabled: Boolean;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiMgr := TJWifiManager.Wrap((obj as ILocalObject).GetObjectID);
  WifiIsEnabled := WifiMgr.isWifiEnabled;
  ...
end;


The equivilent in C++ is:

#include <Androidapi.Helpers.hpp>
#include <Androidapi.JNI.Net.hpp>
 
_di_JObject obj = SharedActivityContext()->getSystemService(TJContext::JavaClass->WIFI_SERVICE);
_di_JWifiManager WifiMgr = TJWifiManager::Wrap(((_di_ILocalObject)obj)->GetObjectID());
bool WifiIsEnabled = WifiMgr->isWifiEnabled();
...


,
talks about generating DELPHI native bridge files from JAR libraries. I
am not sure if the Java2OP.exe is what I need to use for C++ or is
there any other tool for it?

You can add a Delphi .pas file to a C++ project, and a corresponding C++
.hpp file will be created when the .pas file is compiled. You can then #include
that .hpp file in your C++ code.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Does XE8 C++, have an equivalent class like native WiFiManager(ANDROID) [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2015 5:23 PM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama wrote:

*Here is the code snippet. I am getting undefined identifier
Wifimanager error during compile time.*

That is because you are using the wrong class name. Try this instead:

#include <Androidapi.Helpers.HPP>
#include <Androidapi.JNI.Net.HPP>
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int wifistate;
    _di_JObject obj = SharedActivityContext()->getSystemService(TJContext::JavaClass->WIFI_SERVICE);
    _di_JWifiManager wm = TJWifiManager::Wrap(((_di_ILocalObject)obj)->GetObjectID());
    wifistate = wm->isWifiEnabled();
    Label1->Text = wifistate;
}


--
Remy Lebeau (TeamB)
Anupama Annambh...

Posts: 24
Registered: 1/16/15
Re: Does XE8 C++, have an equivalent class like native WiFiManager(ANDROID) [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2015 5:55 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks a Ton Remy Lebeau. That worked like a charm!

Your responses are very knowledgeable and detail oriented.
I appreciate all the time and help you spent providing the answers.

Anu
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02