C ++ Builder 10.2 Tokyo. JNI. BroadcastReceiver Android
April 3, 2017 by Luis Felipe
April 3, 2017 by Luis Felipe
[SHOWTOGROUPS=4,20]
This time we will see how to capture in C ++ Builder the onReceive event , from a BroadcastReceiver made in Java Android , in our case every time a change in device connectivity is detected, for example, we connect or disconnect from a WIFI network , we have data through the cellular network; This also serves as a basis for determining when we are without the Internet.
To achieve the objective we must follow the following steps:
We must create an Android library using the ADT (Android Developer Tool), which will have the implementation of the BroadcastReceiver. This Android Java class must have the signature of a native method , which must be static and public so that it can be implemented / registered in C ++ Builder. This library will be compiled into a .aar file , we will unzip it and use the classes.jar file .
We create a Project in C ++ Builder and add the Android library in the Android section in Libraries.
We write the necessary code to register the Native Method through JNI .
As you will notice in the previous image, a routine called nativeOnReceive is referenced in the JNINativeMethod structure , it must have a specific signature, as we will see in the following image:
As a last step we must modify the Android Manifest file of our project and add the BroadcastReceiver ..
What we have left is to add the different necessary permissions as the case may be, in this case you must add the following permissions.
Those who are used to my videos, don't worry, we will have a video step by step.
[/SHOWTOGROUPS]
This time we will see how to capture in C ++ Builder the onReceive event , from a BroadcastReceiver made in Java Android , in our case every time a change in device connectivity is detected, for example, we connect or disconnect from a WIFI network , we have data through the cellular network; This also serves as a basis for determining when we are without the Internet.
To achieve the objective we must follow the following steps:
We must create an Android library using the ADT (Android Developer Tool), which will have the implementation of the BroadcastReceiver. This Android Java class must have the signature of a native method , which must be static and public so that it can be implemented / registered in C ++ Builder. This library will be compiled into a .aar file , we will unzip it and use the classes.jar file .

We create a Project in C ++ Builder and add the Android library in the Android section in Libraries.

We write the necessary code to register the Native Method through JNI .

As you will notice in the previous image, a routine called nativeOnReceive is referenced in the JNINativeMethod structure , it must have a specific signature, as we will see in the following image:

As a last step we must modify the Android Manifest file of our project and add the BroadcastReceiver ..

What we have left is to add the different necessary permissions as the case may be, in this case you must add the following permissions.

Those who are used to my videos, don't worry, we will have a video step by step.
[/SHOWTOGROUPS]