We introduce the brief documentation of KSWEB library: KSWEBLib v1.21.
You can get the link for library downloading by your request.
Here you can see a steps which you need to do for the library using.
1) First of all you need to have permission Manifest.permission.WRITE_EXTERNAL_STORAGE for your app. You must request it in your code like this:
final int PERMISSIONS_REQUEST_WRITE_STORAGE = 112; boolean hasPermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); if (!hasPermission) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_STORAGE); } else { //your business logic }
2) The second step. You need to initialize the class Worker after you got the necessary permissions.
final String SERIAL_KEY = "your_serial_key"; final Worker worker = new Worker(this); worker.init(new InitDoneListener() { @Override public void onInitDone(InitResponseStatus status) { if (status == InitResponseStatus.OK) { //if initialization completes without error } if (status == InitResponseStatus.ERROR) { //if initialization completes with errors. For example, your license is invalid } } }, SERIAL_KEY);
Class Worker is the base class of KSWEBLib that provides you basic API. It contains the followings public methods which is available for you after initialization was done:
//Makes initialization of Worker public void init(InitDoneListener initDoneListener, final String serialKey); //Starts MySQL server public void startMySQL(ServerStartListener serverStartListener); //Returns true if MySQL server was started successfuly public boolean isMySQLStarted(); //Stop MySQL server public void stopMySQL(); //Start PHP //public void startPHP(final ServerStartListener serverStartListener); //Returns true if PHP started public boolean isPHPStarted(); //Stops PHP public void stopPHP(); //Starts lighttpd server public void startLighttpd(final ServerStartListener serverStartListener); //Returns true if lighttpd was started public boolean isLighttpdStarted(); //Stops lighttpd server public void stopLighttpd(); //Stops all server at once public void stopAllServers();
3) After Worker init was completed in the first time KSWEBLib will install all components in internal device's memory. Also it creates folder "/mnt/sdcard/htdocs" and "/mnt/sdcard/ksweb". So your web content must be placed to the folder "/mnt/sdcard/htdocs"!
Besides, KSWEBLib checks update of components on our server and if they are available it will open dialog which allows to start auto updating. User must restart app after updating will be completed.
If you want to customize the components of KSWEBLib such as version of servers, configurations or something else, please, contact us: contact us.Here you can see the example of typical using of KSWEBLib:
import android.Manifest; import android.content.pm.PackageManager; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import ru.kslabs.ksweblib.InitDoneListener; import ru.kslabs.ksweblib.InitResponseStatus; import ru.kslabs.ksweblib.ServerStartListener; import ru.kslabs.ksweblib.Worker; public class DemoActivity extends AppCompatActivity { static boolean firstOnCreate = true; public static final int PERMISSIONS_REQUEST_WRITE_STORAGE = 112; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (firstOnCreate ) { firstOnCreate = false; //Request sdcard write permission boolean hasPermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); if (!hasPermission) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_STORAGE); } else { init(); } //-------------------------------- } } public void init() { final String SERIAL_KEY = "your_serial_key"; final Worker worker = new Worker(this); worker.init(new InitDoneListener() { @Override public void onInitDone(InitResponseStatus status) { if (status == InitResponseStatus.OK) { if (!worker.isLighttpdStarted()) { worker.startLighttpd(new ServerStartListener() { @Override public void onServerStarted(boolean started) { if (started) { //Server started } else { //Error } } }); } else { //Server already started } //........... The rest of the servers are started in the same way. } if (status == InitResponseStatus.ERROR) { //Worker init with errors. Maybe something wrong with your license? } } }, SERIAL_KEY); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PERMISSIONS_REQUEST_WRITE_STORAGE) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //Permission granted init(); } else { //Permission not granted. In this case probably initialization will pass with errors. init(); } } } }
We hope that our library will help you in developing applications for Android, which require a web server, PHP and MySQL.