文档介绍:PC客户端与Android办事端的Socket同步通信(USB) 收藏
需求:
,作为socket的办事器端;用于吸收Pc client端发来的命令,来处置惩罚数据后,把结果发给PC client
,作为socket的客户端,用于给android手机端发操纵命令
难点阐发:
,即插上USB线时马上提示的对话框选adb。很多多少敌手机的操纵都可以用adb直接作。
不外,我发明LG GW880就没有,要去下载个
“”
,一定要用adb forward 来作下端口转发才气连上socket.
view plaincopy to clipboardprint?
().exec("adb forward tcp:12580 tcp:10086");
(3000);
().exec("adb forward tcp:12580 tcp:10086");
(3000);
,但是还要有要领来从PC的client端来启动手机上的service ,这个措施可以通过PC端adb命令来发一个Broastcast ,手机端再写个吸收BroastcastReceive来吸收这个Broastcast,在这个BroastcastReceive来启动service
pc端命令:
view plaincopy to clipboardprint?
().exec(
"adb shell am broadcast -a NotifyServiceStart");
().exec(
"adb shell am broadcast -a NotifyServiceStart");
view plaincopy to clipboardprint?
package ;
import ;
import ;
import ;
import ;
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) {
(, ().getName() + "---->"
+ "ServiceBroadcastReceiver onReceive");
String action = ();
if ((action)) {
(new Intent(context, ));
(, ().getName() + "---->"
+ "Servi