Articles - C ++ Builder 10.2 Tokyo. JNI. BroadcastReceiver Android by Luis Felipe | BESK.SU - программирование без границ (c) 2025

Articles C ++ Builder 10.2 Tokyo. JNI. BroadcastReceiver Android by Luis Felipe

emailx45

Местный
Credits
513
C ++ Builder 10.2 Tokyo. JNI. BroadcastReceiver Android
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 .

BroacastReceiver_Java_Android


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

ProjectManager


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

JNI_Native_Method_Registration


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:

Signature_MethodNative_Cpp


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

Manifest_CBuilder


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.

Screen Shot 2017-04-02 at 4.52.12 PM


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

[/SHOWTOGROUPS]
 
Сверху