add server
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.github.penfeizhou.doricdemo">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:name="com.github.penfeizhou.doricdemo.MyApplication"
|
||||
android:allowBackup="true"
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package com.github.penfeizhou.doricdemo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doricdemo
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-08-03
|
||||
*/
|
||||
public class LocalServer extends NanoHTTPD {
|
||||
private final Context context;
|
||||
|
||||
public LocalServer(Context context, int port) {
|
||||
super(port);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response serve(IHTTPSession session) {
|
||||
String url = session.getUri();
|
||||
if (url.startsWith("/assets/")) {
|
||||
String fileName = url.substring("/assets/".length());
|
||||
AssetManager assetManager = context.getAssets();
|
||||
try {
|
||||
InputStream inputStream = assetManager.open(fileName);
|
||||
return newFixedLengthResponse(Response.Status.OK, "text/plain", inputStream, inputStream.available());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld");
|
||||
}
|
||||
}
|
@@ -5,10 +5,13 @@ import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.github.penfeizhou.doric.Doric;
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.utils.DoricUtils;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -22,6 +25,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
.put("height", ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
doricContext.callEntity("log");
|
||||
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
|
||||
Doric.connectDevKit("wss://192.168.11.38:7777");
|
||||
LocalServer localServer = new LocalServer(getApplicationContext(), 8910);
|
||||
try {
|
||||
localServer.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user