博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 下 JNI 开发
阅读量:4047 次
发布时间:2019-05-25

本文共 1373 字,大约阅读时间需要 4 分钟。

6.C代码调用Android浏览器

 

 

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");

    }

 

}

 

 

本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源。

你可能感兴趣的文章
Linux常用统计命令之wc
查看>>
测试必会之 Linux 三剑客之 sed
查看>>
Socket请求XML客户端程序
查看>>
Java中数字转大写货币(支持到千亿)
查看>>
Java.nio
查看>>
函数模版类模版和偏特化泛化的总结
查看>>
VMware Workstation Pro虚拟机不可用解决方法
查看>>
最简单的使用redis自带程序实现c程序远程访问redis服务
查看>>
redis学习总结-- 内部数据 字符串 链表 字典 跳跃表
查看>>
iOS 对象序列化与反序列化
查看>>
iOS 序列化与反序列化(runtime) 01
查看>>
iOS AFN 3.0版本前后区别 01
查看>>
iOS ASI和AFN有什么区别
查看>>
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>
iOS app之间的跳转以及传参数
查看>>
iOS __block和__weak的区别
查看>>
Android(三)数据存储之XML解析技术
查看>>
Spring JTA应用之JOTM配置
查看>>
spring JdbcTemplate 的若干问题
查看>>