JNI 开发经典案例之——卸载APK 跳转到特定网页(一般为反馈页面)学习
2017-06-29 21:45
453 查看
假设你已经是JNI 老司机:
public class NativeUtils {
static {
System.loadLibrary(“native-lib”);
}
public static native void init();
}
2,c 代码部分
JNIEXPORT void JNICALL Java_com_org_gsc_shouhujnidemo_NativeUtils_init
(JNIEnv * env, jclass jclass1) {
//初始化log
//初始化log
LOGI(“init start…”);
}
3.调用 sever 或者Act
NativeUtils.init();
列表内容
public class NativeUtils {
static {
System.loadLibrary(“native-lib”);
}
public static native void init();
}
2,c 代码部分
JNIEXPORT void JNICALL Java_com_org_gsc_shouhujnidemo_NativeUtils_init
(JNIEnv * env, jclass jclass1) {
//初始化log
//初始化log
LOGI(“init start…”);
//fork子进程,以执行轮询任务 pid_t pid = fork(); if (pid < 0) { //出错log LOGI("fork failed..."); } else if (pid == 0) { //子进程注册"/data/data/com.example.uninstallprompt"目录监听器 int fileDescriptor = inotify_init(); if (fileDescriptor < 0) { LOGI("inotify_init failed..."); exit(1); } int watchDescriptor; watchDescriptor = inotify_add_watch(fileDescriptor,"/data/data/com.org.gsc.shouhujnidemo", IN_DELETE); LOGI("watchDescriptor=%d",watchDescriptor); if (watchDescriptor < 0) { LOGI("inotify_add_watch failed..."); exit(1); } //分配缓存,以便读取event,缓存大小=一个struct inotify_event的大小,这样一次处理一个event void *p_buf = malloc(sizeof(struct inotify_event)); if (p_buf == NULL) { LOGI("malloc failed..."); exit(1); } //开始监听 LOGI("start observer..."); size_t readBytes = read(fileDescriptor, p_buf,sizeof(struct inotify_event)); //read会阻塞进程,走到这里说明收到目录被删除的事件,注销监听器 free(p_buf); inotify_rm_watch(fileDescriptor, IN_DELETE); //目录不存在log LOGI("uninstall"); //执行命令am start -a android.intent.action.VIEW -d http://shouji.360.cn/web/uninstall/uninstall.html //execlp( // "am", "am", "start", "-a", "android.intent.action.VIEW", "-d", // "http://shouji.360.cn/web/uninstall/uninstall.html", (char *)NULL); //4.2以上的系统由于用户权限管理更严格,需要加上 --user 0 execlp("am", "am", "start", "--user", "0", "-a", "android.intent.action.VIEW", "-d", "https://www.baidu.com",(char *) NULL); } else { //父进程直接退出,使子进程被init进程领养,以避免子进程僵死 }
}
3.调用 sever 或者Act
NativeUtils.init();
列表内容
相关文章推荐
- html学习笔记(四)——点击div实现网页页面跳转
- Android不被kill的Service与卸载之后跳转出反馈页面
- Android卸载程序之后跳转到指定的反馈页面
- .Net语言 APP开发平台——Smobiler学习日志:如何实现快速跳转网页
- Android卸载程序之后跳转到指定的反馈页面
- 在Java Web开发中,经常会用到跳转页面的方法,一般有下面两种方法。
- Django 开发学习笔记(7)- 开发特定主题显示的页面
- 混合开发的大趋势之一React Native之页面跳转(2)+物理返回+特定平台代码
- Android卸载程序之后跳转到指定的反馈页面
- Android卸载程序之后跳转到指定的反馈页面
- Android卸载程序之后跳转到指定的反馈页面
- Android使用JNI调用C/C++生成的.so库的流程(功能:apk卸载时调用web页面)
- Android卸载程序之后跳转到指定的反馈页面
- (仿360卸载后弹窗)Android卸载程序之后跳转到指定的反馈页面
- Android卸载程序之后跳转到指定的反馈页面
- 详解Android App卸载后跳转到指定的反馈页面的方法
- 混合开发的大趋势之一React Native之页面跳转(2)+物理返回+特定平台代码
- Android卸载程序之后跳转到指定的反馈页面
- OAF_开发系列18_实现OAF页面跳转setForwardURL / forwardImmediately(案例)
- 【ios开发学习 - 第一课】页面跳转