54次浏览

制作安卓adb调试小工具-qt

做这小工具完全是闹着玩,感觉adb挺有趣的。

我介绍下使用方法,首先手机通过数据线连接电脑,如果没有安装adb驱动,就去下载个360手机助手连接下就ok了,记得软件使用时把有关操作手机软件关闭,比如360手机助手。 驱动安装完毕,点击扫描标识,一个标识代表一个手机,然后填入标识编辑框,执行你想要的操作即可。

软件界面图:

adb工具

成品软件下载

源码下载

程序主要代码:

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    //构造函数
    ui->setupUi(this);
    //设置固定大小
    this->setMaximumSize(391,233);
    this->setMinimumSize(391,233);




}
Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{

    QString biaoshi=ui->lineEdit_2->text();

    QString program="adb\\adb.exe -s ";
    program+=biaoshi;
    program+=" shell am start -n com.tencent.mm/.ui.LauncherUI";

    QProcess *myProcess = new QProcess;
    myProcess->start(program);

}

void Widget::on_pushButton_2_clicked()//call
{
    QString startProgram=ui->lineEdit->text();
    if(startProgram.isEmpty())
    {
        //实例化消息对话框对象
            QMessageBox *msgBox;
            msgBox = new QMessageBox("erro!","The mobile phone number is empty! ",QMessageBox :: NoIcon, QMessageBox::Ok | QMessageBox::Default, NULL,0);

            msgBox->show();
        return;
    }

    QString biaoshi=ui->lineEdit_2->text();

    QString program="adb\\adb.exe -s ";
    program+=biaoshi;
    program+=" shell am start -a android.intent.action.CALL tel:";

    program+=startProgram;

    QProcess *myProcess = new QProcess;
    myProcess->start(program);



}

void Widget::on_pushButton_saomiao_clicked()//扫描地址按钮
{

    ui->textEdit->clear();//清空编辑框内容
    QStringList arguments;
    arguments << "devices";


    QProcess process(this);
    process.start("adb\\adb.exe", arguments);
    process.waitForStarted();
    process.waitForFinished();
    QString strResult = QString::fromLocal8Bit(process.readAllStandardOutput());

   strResult=strResult.trimmed();//去除两端空格


    QStringList list = strResult.split("\n");//按行分割字符串
    foreach(QString str, list)
    {
       str.remove(QString("device"), Qt::CaseInsensitive);
       str.remove(QString("List of s attached"), Qt::CaseInsensitive);

       ui->textEdit->append(str.trimmed());
    }
    int siz=list.size();

    QMessageBox *msgBox;
     msgBox = new QMessageBox("Citext","siz: "+QString::number(siz-1)
      ,QMessageBox :: NoIcon, QMessageBox::Ok | QMessageBox::Default, NULL,0);

     msgBox->show();

}

void Widget::on_pushButton_saomiao_2_clicked()//执行adb命令按钮
{

    QString biaoshi=ui->lineEdit_2->text();

    QString program="adb\\adb.exe -s ";
    program+=biaoshi;
    program+=" ";
    program+=ui->lineEdit_5->text();

    QProcess *myProcess = new QProcess;
    myProcess->start(program);


}

void Widget::on_pushButton_3_clicked()//所以标识打开微信
{

    QString str;
    str=ui->textEdit->toPlainText();

    QStringList list = str.split("\n");//按行分割字符串
    foreach (QString str, list)
    {
        if(!str.isEmpty())
        {
            QString program="adb\\adb.exe -s ";
            program+=str;
            program+=" shell input keyevent 26";

            QProcess *myProcess = new QProcess;
            myProcess->start(program);

        }



    }

   /* QMessageBox *msgBox;
    msgBox = new QMessageBox("  ",str
     ,QMessageBox :: NoIcon, QMessageBox::Ok | QMessageBox::Default, NULL,0);

    msgBox->show();*/


}

发表评论

电子邮件地址不会被公开。 必填项已用*标注