APK:网络adb

Posted Gatsby

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了APK:网络adb相关的知识,希望对你有一定的参考价值。

 一、网络adb

1.1、device ockchipcommoninit.rk30board.rc

# for Internet adb
on property:netadb.status=true
    setprop service.adb.tcp.port 5555
    restart adbd

# for Internet adb
on property:netadb.status=false
    setprop service.adb.tcp.port 0
    restart adbd

1.2、连接

adb connect 192.168.1.1:5555
adb disconnect 192.168.1.1
切回usb模式 adb usb

三、仙逆

3.1、androidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gatsby.zebra"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <uses-sdk
        android:minSdkVersion="22"
        android:targetSdkVersion="22" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />   
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".ZebraReceiver">
             <intent-filter>
               <action android:name="com.gatsby.action.MCU_WIFI_ADB_Y"/>
               <action android:name="com.gatsby.action.MCU_WIFI_ADB_N"/>
             </intent-filter>
        </receiver>
        
    </application>

</manifest>

 3.2、activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.gatsby.zebra.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#F9F900"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        android:shadowRadius="3.0"
        android:text="EthernetStat: "
        android:textColor="#4A4AFF"
        android:textSize="60sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#F9F900"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        android:shadowRadius="3.0"
        android:text="EthernetIP: "
        android:textColor="#4A4AFF"
        android:textSize="60sp" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="#40BBFA"
        android:text="Start Net ADB"
        android:textSize="40sp" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="#BF4507"
        android:text="Stop Net ADB"
        android:textSize="40sp" />

</LinearLayout>

3.3、MainActivity.java

package com.gatsby.zebra;

import android.app.Activity;
import android.content.Intent;

import com.android.xhapimanager.XHApiManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

    private String TAG = "Gatsby";

    XHApiManager apimanager;
    private TextView state, ip;
    private Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        apimanager = new XHApiManager();

        state = (TextView) findViewById(R.id.textView1);
        ip = (TextView) findViewById(R.id.textView2);

        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);

        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

        state.setText("EthernetStat: " + apimanager.XHEthernetState() + "");
        ip.setText("EthernetIP: " + apimanager.XHEthernetGetIP());

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {
        case R.id.btn1:
            Intent intentY = new Intent();
            intentY.setAction("com.gatsby.action.MCU_WIFI_ADB_Y");
            sendBroadcast(intentY);
            break;
        case R.id.btn2:
            Intent intentN = new Intent();
            intentN.setAction("com.gatsby.action.MCU_WIFI_ADB_N");
            sendBroadcast(intentN);
            break;

        }

    }
}

 

3.4、ZebraReceiver.java

package com.gatsby.zebra;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ZebraReceiver extends BroadcastReceiver {

    private final String MCU_WIFI_ADB_Y = "com.gatsby.action.MCU_WIFI_ADB_Y";
    private final String MCU_WIFI_ADB_N = "com.gatsby.action.MCU_WIFI_ADB_N";

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if (MCU_WIFI_ADB_Y.equals(intent.getAction())) {
            Log.e("gatsby", "MCU_WIFI_ADB_Y ");
            RootCommand("stop adbd");
            RootCommand("setprop service.adb.tcp.port 5555");
            RootCommand("start adbd");

        } else if (MCU_WIFI_ADB_N.equals(intent.getAction())) {
            Log.e("gatsby", "MCU_WIFI_ADB_N ");
            RootCommand("stop adbd");
            RootCommand("setprop service.adb.tcp.port 0");
            RootCommand("start adbd");
        }
    }

    private void RootCommand(String cmd) {
        Process process = null;
        DataOutputStream os = null;
        DataInputStream is = null;
        try {
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "
");
            os.writeBytes("exit
");
            os.flush();

            int aa = process.waitFor();
            is = new DataInputStream(process.getInputStream());

            byte[] buffer = new byte[is.available()];
            is.read(buffer);

            String out = new String(buffer);
            // Log.d(TAG, out + aa);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                if (is != null) {
                    is.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
    }
}

 

技术图片

 

以上是关于APK:网络adb的主要内容,如果未能解决你的问题,请参考以下文章

怎么通过adb将apk安装到指定设备上

adb工具如何连接手机安装apk

adb工具如何连接手机安装apk

ADB命令安装APK常见错误总结

adb方式在电视端安装apk并调试

adb 安装apk 命令