电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

PC客户端与Android服务端的Socket同步通信VIP免费

PC客户端与Android服务端的Socket同步通信_第1页
1/38
PC客户端与Android服务端的Socket同步通信_第2页
2/38
PC客户端与Android服务端的Socket同步通信_第3页
3/38
第1页共38页编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第1页共38页PC客户端与Android服务端的Socket同步通信(USB)收藏需求:1.一个android端的service后台运行的程序,作为socket的服务器端;用于接收Pcclient端发来的命令,来处理数据后,把结果发给PCclient2.PC端程序,作为socket的客户端,用于给android手机端发操作命令难点分析:1.手机一定要有adb模式,即插上USB线时马上提示的对话框选adb。好多对手机的操作都可以用adb直接作。不过,我发现LGGW880就没有,要去下载个2.android默认手机端的IP为“127.0.0.1”3.要想联通PC与android手机的sokcet,一定要用adbforward来作下端口转发才能连上socket.viewplaincopytoclipboardprint?Runtime.getRuntime().exec("adbforwardtcp:12580tcp:10086");Thread.sleep(3000);Runtime.getRuntime().exec("adbforwardtcp:12580tcp:10086");Thread.sleep(3000);4.android端的service程序Install到手机上容易,但是还要有方法来从PC的client端来启动手机上的service,这个办法可以通过PC端adb命令来发一个Broastcast,手机端再写个接收BroastcastReceive来接收这个Broastcast,在这个BroastcastReceive来启动servicepc端命令:viewplaincopytoclipboardprint?Runtime.getRuntime().exec("adbshellambroadcast-aNotifyServiceStart");Runtime.getRuntime().exec("adbshellambroadcast-aNotifyServiceStart");android端的代码:ServiceBroadcastReceiver.javaviewplaincopytoclipboardprint?第2页共38页第1页共38页编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第2页共38页packagecom.otheri.service;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.util.Log;publicclassServiceBroadcastReceiverextendsBroadcastReceiver{privatestaticStringSTART_ACTION="NotifyServiceStart";privatestaticStringSTOP_ACTION="NotifyServiceStop";@OverridepublicvoidonReceive(Contextcontext,Intentintent){Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceive");Stringaction=intent.getAction();if(START_ACTION.equalsIgnoreCase(action)){context.startService(newIntent(context,androidService.class));Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceivestartend");}elseif(STOP_ACTION.equalsIgnoreCase(action)){context.stopService(newIntent(context,androidService.class));Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceivestopend");}}}packagecom.otheri.service;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.util.Log;publicclassServiceBroadcastReceiverextendsBroadcastReceiver{privatestaticStringSTART_ACTION="NotifyServiceStart";privatestaticStringSTOP_ACTION="NotifyServiceStop";@OverridepublicvoidonReceive(Contextcontext,Intentintent){第3页共38页第2页共38页编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第3页共38页Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceive");Stringaction=intent.getAction();if(START_ACTION.equalsIgnoreCase(action)){context.startService(newIntent(context,androidService.class));Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceivestartend");}elseif(STOP_ACTION.equalsIgnoreCase(action)){context.stopService(newIntent(context,androidService.class));Log.d(androidService.TAG,Thread.currentThread().getName()+"---->"+"ServiceBroadcastReceiveronReceivestopend");}}}5.由于是...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

PC客户端与Android服务端的Socket同步通信

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部