This guide provides instructions for integrating the Fleetshare SDK into any Windows application, regardless of the programming language used.
Overview
The Generic Windows Integration method allows you to incorporate the Fleetshare SDK into your Windows application using a provided executable file. This approach is versatile and can be implemented in any programming language that supports running subprocesses.
Prerequisites
Before you begin, ensure you have:
Successfully applied and been accepted into the Fleetshare SDK program.
Received your API key from the EarnFM dashboard.
Obtained the earnfm_sdk.exe file from the Fleetshare team.
Integration Steps
Obtain the SDK Executable
The Fleetshare team will provide you with earnfm_sdk.exe after your application to the SDK program is approved.
This executable is signed with our extended validation certificate for security.
Include the Executable in Your Application
Place the earnfm_sdk.exe file in an appropriate directory within your application’s file structure.
User Consent
Before running the SDK, ensure you have obtained user consent for sharing their data.
Execute the SDK
Run the SDK executable as a subprocess within your application.
Use the following command format:
earnfm_sdk.exe <your_api_key>
Replace <your_api_key> with the API key provided by EarnFM.
Subprocess Management
Implement appropriate subprocess management in your application to start, monitor, and stop the SDK executable as needed.
Example Implementation
Here’s an example of running the Fleetshare SDK in the background with a hidden console window using Node.js:
const{spawn}=require('child_process');constapiKey='YOUR_API_KEY';// Function to start the SDK
functionstartSDK(){constsdkProcess=spawn('earnfm_sdk.exe',[apiKey],{detached:true,stdio:'ignore',windowsHide:true// This hides the console window on Windows
});sdkProcess.unref();console.log('Fleetshare SDK started in the background');}// Start the SDK
startSDK();// Your main program continues here
console.log('Main program is running...');// ... rest of your application logic
Here’s an example of running the Fleetshare SDK in a background thread with a hidden console window using C#:
usingSystem;usingSystem.Diagnostics;usingSystem.Threading.Tasks;classProgram{staticasyncTaskMain(){stringapiKey="YOUR_API_KEY";// Start the SDK in a background taskTasksdkTask=Task.Run(()=>RunSDK(apiKey));// Your main program continues hereConsole.WriteLine("Main program is running...");// ... rest of your application logic// Optionally, wait for the SDK task to completeawaitsdkTask;}staticvoidRunSDK(stringapiKey){using(Processprocess=newProcess()){process.StartInfo.FileName="earnfm_sdk.exe";process.StartInfo.Arguments=apiKey;process.StartInfo.UseShellExecute=false;process.StartInfo.CreateNoWindow=true;process.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;process.Start();process.WaitForExit();}}}
Here’s an example of running the Fleetshare SDK in a background thread with a hidden console window using Java:
importjava.io.IOException;publicclassFleetshareSDKExample{publicstaticvoidmain(String[]args){StringapiKey="YOUR_API_KEY";// Start the SDK in a separate thread
ThreadsdkThread=newThread(()->runSDK(apiKey));sdkThread.start();// Your main program continues here
System.out.println("Main program is running...");// ... rest of your application logic
}privatestaticvoidrunSDK(StringapiKey){try{ProcessBuilderprocessBuilder=newProcessBuilder("earnfm_sdk.exe",apiKey);// Hide the console window (Windows-specific)
processBuilder.inheritIO();processBuilder.redirectOutput(ProcessBuilder.Redirect.DISCARD);processBuilder.redirectError(ProcessBuilder.Redirect.DISCARD);Processprocess=processBuilder.start();intexitCode=process.waitFor();System.out.println("SDK exited with code: "+exitCode);}catch(IOException|InterruptedExceptione){e.printStackTrace();}}}
Best Practices
Error Handling: Implement robust error handling for scenarios where the executable might fail to start or unexpectedly terminate.
User Control: Provide users with options to start and stop the bandwidth sharing process.
Update Mechanism: Consider implementing a mechanism to update the SDK executable when new versions are released. As we may disable outdated versions after a certain period.