因为要做零流量分享 ,所有首先你得了解其原理。 一台手机 开启了热点 另一台手机一扫对方二维码 就可以下载对方手机上的应用了。 不需要你得手机有 移动网络,前提是
你连上对方手机开启的热点。
现在 说说大概的原理
安装了茄子或者快牙的手机 当进入零流量分享界面时 会开启热点 毋庸置疑。 其实在后台 : 茄子是 2999端口 快牙是 7989 端口。
ServerSocket = new ServerSocket ( 2999 ); 这是茄子的 。
ServerSocket = new ServerSocket (7989) ; 这是快牙的 。
监听到请求怎么办? 看下面代码:
System.out.println(filePath + " requested.");
outstream.println("HTTP/1.1 200 OK");
outstream.println("MIME-version:1.0");
// outstream.println("Content_Type:text/html");
outstream.println("Content-Type:application/octet-stream");
int len = (int) file.length();
// outstream.println("Location:" + filePath);
outstream.println("Content-Length:" + len);
Log.d(TAG, "len: " + len);
outstream.println("Connection:close");
// outstream.println("Accept-Ranges:bytes");
outstream.println("");
sendPPt(outstream, filePath);
// outstream.println("");
outstream.flush();
这是接到请求 后处理请求 , 把 自己的 应用发给 对方 用的是 http 协议 ,因为 对方使用的是 浏览器下载。