An instance of automatic startup service in Android
Recently, hevsocks5client was ported to Android. After adding system call support related to signalfd and timerfd, you can directly compile executable using NDK. Direct native exectuable is always inconvenient to use in Android system. Let's make it an APK. Temporarily, only write a service and start it automatically without activity.
Calling native program in Java, I choose to use JNI mode, directly in JNI_. Calling pthread_ in the OnLoad method Create create a thread and run the original main.
Android services
The service mainly loads the HEV Socks5 client library of JNI interface to make the service run.
BroadcastReceiver
The function of servicereceiver is to monitor the boot on the system_ The completed event is used to automatically start the service.
AndroidManifest.xml
Finally, register the service and receiver in the manifest, and increase the permissions to access the Internet and boot completed.
Tips
This method is only valid in Android 2.3.3 and earlier versions. If this application has never been run in later versions after installation, the broadcast receiver will not receive the boot completed action. The solution is to manually start the service with the command.