PC客户端与Android服务端的Socket同步通信(2).pdf

PC客户端与Android服务端的Socket同步通信(2).pdf

  1. 1、本文档共37页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
PC 客户端与Android 服务端的Socket 同步通信(USB ) 1.一个android 端的service 后台运行的程序,作为socket 的服务器端;用于接收Pc client 端发来的命令,来处理数据后,把结果发给PC client 2.PC 端程序,作为socket 的客户端,用于给android 手机端发操作命令 难点分析: 1.手机一定要有adb 模式,即插上USB 线时马上提示的对话框选 adb 。好多对手机的 操作都可以用adb 直接作。 不过,我发现LG GW880 就没有,要去下载个 2.android 默认手机端的IP 为“” 3.要想联通PC 与android 手机的sokcet,一定要用adb forward 来作下端口转发才能连 上socket. view plaincopy to clipboardprint? Runtime.getRuntime().exec(adb forward tcp:12580 tcp:10086); Thread.sleep(3000); Runtime.getRuntime().exec(adb forward tcp:12580 tcp:10086); Thread.sleep(3000); 4.android 端的 service 程序Install 到手机上容易,但是还要有方法来从PC 的client 端来启动手机上的 service ,这个办法可以通过PC 端 adb 命令来发一个Broastcast ,手机 端再写个接收 BroastcastReceive 来接收这个 Broastcast ,在这个 BroastcastReceive 来启动 service pc 端命令: view plaincopy to clipboardprint? Runtime.getRuntime().exec( adb shell am broadcast -a NotifyServiceStart); Runtime.getRuntime().exec( adb shell am broadcast -a NotifyServiceStart); android 端的代码:ServiceBroadcastReceiver.java view plaincopy to clipboardprint? package com.otheri.service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ServiceBroadcastReceiver extends BroadcastReceiver { private static String START_ACTION = NotifyServiceStart; private static String STOP_ACTION = NotifyServiceStop; @Override public void onReceive(Context context, Intent intent) { Log.d(androidService.TAG, Thread.currentThread().getName() + + ServiceBroadcastReceiver onReceive); String action = intent.getAction(); if (START_ACTION.equalsIgnoreCase(action)) { context.startService(new Intent(context, androidService.class)); Log.d(androidService.TAG, Thread.currentThread

文档评论(0)

新起点 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档