adb操纵模拟器代码

//运行android模拟器中的app
void BlueStackApi::RunApp(char *AppName){
    //连接到模拟器
    char adb[MAX_PATH]={0};
    char connectParam[MAX_PATH]={0};
    sprintf_s(adb,MAX_PATH,"%s%s",m_blueStackPath,"HD-Adb.exe");
    sprintf_s(connectParam,MAX_PATH,"connect 127.0.0.1:%d",m_adbPort);
    ShellExecute(0,"open",adb,connectParam,"",0);
    //运行adb启动app
    char appParam[MAX_PATH]={0};
    sprintf_s(appParam,MAX_PATH,"shell am start -n %s",AppName);
    ShellExecute(0,"open",adb,appParam,"",0);
}


//关闭android模拟器中的app
void BlueStackApi::StopApp(char *AppName){
    //连接到模拟器
    char adb[MAX_PATH]={0};
    char connectParam[MAX_PATH]={0};
    sprintf_s(adb,MAX_PATH,"%s%s",m_blueStackPath,"HD-Adb.exe");
    sprintf_s(connectParam,MAX_PATH,"connect 127.0.0.1:%d",m_adbPort);
    ShellExecute(0,"open",adb,connectParam,"",0);
    //运行adb启动app
    char appParam[MAX_PATH]={0};
    sprintf_s(appParam,MAX_PATH,"shell pm clear %s",AppName);
    ShellExecute(0,"open",adb,appParam,"",0);
}

//安装app
void BlueStackApi::InstallApk(char *apkName){
    //连接到模拟器
    char adb[MAX_PATH]={0};
    char connectParam[MAX_PATH]={0};
    sprintf_s(adb,MAX_PATH,"%s%s",m_blueStackPath,"HD-Adb.exe");
    sprintf_s(connectParam,MAX_PATH,"connect 127.0.0.1:%d",m_adbPort);
    ShellExecute(0,"open",adb,connectParam,"",0);
    //运行adb启动app
    char appParam[MAX_PATH]={0};
    sprintf_s(appParam,MAX_PATH,"install %s",apkName);
    ShellExecute(0,"open",adb,appParam,"",0);
}
//卸载app
void BlueStackApi::UnInstallApk(char *apkName){
    //连接到模拟器
    char adb[MAX_PATH]={0};
    char connectParam[MAX_PATH]={0};
    sprintf_s(adb,MAX_PATH,"%s%s",m_blueStackPath,"HD-Adb.exe");
    sprintf_s(connectParam,MAX_PATH,"connect 127.0.0.1:%d",m_adbPort);
    ShellExecute(0,"open",adb,connectParam,"",0);
    //运行adb启动app
    char appParam[MAX_PATH]={0};
    sprintf_s(appParam,MAX_PATH,"uninstall %s",apkName);
    ShellExecute(0,"open",adb,appParam,"",0);
}

你可能感兴趣的:(adb操纵模拟器代码)