本文共 1373 字,大约阅读时间需要 4 分钟。
Dos命令行中打开浏览器:
adb shell am start -a android.intent.action.VIEW -d
adb shell am start -a android.intent.action.VIEW -d http://192.168.30.165:8080/uninstall.html
C语言中通过execlp方法打开浏览器:
execlp("am", "am", "start", "-a", "android.intent.action.VIEW", "-d", "http://www.atguigu.com", NULL);
命令:
# am start -a android.intent.action.VIEW -d
am start -a android.intent.action.VIEW -d /uninstall.html
全命令:
execlp("am", "am", "start", "-a", "android.intent.action.VIEW", "-d", "http://www.atguigu.com", NULL);
execlp("am", "am", "start", "-a", "android.intent.action.VIEW", "-d", "http://10.0.2.2:8080/uninstall.html", NULL);
C端完整代码:
/**
* 监听当应用卸载
*/
JNIEXPORT void JNICALL Java_com_atguigu_pressuredemo_MainActivity_uninstallListener
(JNIEnv *env, jobject obj){
//此方法会创建一个进程,父进程会返回一个值,子进程也会返回一次值.
int state = fork();
if(state > 0){
//当前是父进程
LOGD("parent process=%d",state);
}else if(state == 0){
//当前是子进程
LOGD("sup process=%d",state);
//监听当前应用是否卸载
int isStop = 1;
FILE* file;
while(isStop){
//每隔1秒钟判断应用目录是否存在
sleep(1);
//FILE *fopen(const char *, const char *);
file = fopen("/data/data/com.atguigu.pressuredemo","r");
if(file == NULL){
//当文件夹没有了,就是被卸载了
LOGD("uninstalled ....");
execlp("am", "am", "start", "-a", "android.intent.action.VIEW", "-d", "http://10.0.2.2:8080/uninstall.html", NULL);
isStop = 0;
}
}
}else{
LOGD("Error");
}
}
本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源。