监听自身应用卸载,并在卸载之后,使用libcurl三方库进行一次三方请求,或者启动网页。

最近研究了一下如何监听自身应用卸载,最后,做了一个sample。

sample 下载地址:http://download.csdn.net/detail/keanbin/6991979

主要代码:

1. 监听本应用卸载,其实是监听应用在内部存储器中的文件夹是否被删除。

ListenUninstallProcess.c

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#include <string.h>
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/inotify.h>

#include "AndroidLog.h"
#include "CurlHttpOperate.h"

/* 宏定义begin */
//清0宏
#define MEM_ZERO(pDest, destSize) memset(pDest, 0, destSize)

//LOG宏定义
#define LOG_INFO(tag, msg) __android_log_write(ANDROID_LOG_INFO, tag, msg)
#define LOG_DEBUG(tag, msg) __android_log_write(ANDROID_LOG_DEBUG, tag, msg)
#define LOG_WARN(tag, msg) __android_log_write(ANDROID_LOG_WARN, tag, msg)
#define LOG_ERROR(tag, msg) __android_log_write(ANDROID_LOG_ERROR, tag, msg)

//#define FEEDBACK_URL "http://www.baidu.com"
//#define LISTEN_FILE_PATH "/data/data/com.keanbin.app"

/* 内全局变量begin */
static jboolean b_IS_COPY = JNI_TRUE;

/*
 * 启动进程,监听指定文件,如果文件被删除,就启动网页。
 *
 * listenFilePathJStr: 监听的文件路径
 * urlJStr: 网址
 */
void Java_com_keanbin_testlistenselfuninstall_ListenUninstallProcess_startBrowser(
		JNIEnv* env, jobject thiz, jstring listenFilePathJStr, jstring urlJStr,
		jint androidSdkVersion) {

	const char *listenFilePath;
	const char *url;

	//初始化log
	LOGI("jni startBrowser()");

	listenFilePath = (*env)->GetStringUTFChars(env, listenFilePathJStr, NULL);
	if (listenFilePath == NULL) {
		return;
	}

	url = (*env)->GetStringUTFChars(env, urlJStr, NULL);
	if (url == NULL) {
		return;
	}

	LOGI("jni startBrowser() listenFilePath = %s , url = %s",
			listenFilePath, url);

	//fork子进程,以执行轮询任务
	pid_t pid = fork();
	if (pid < 0) {
		//出错log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值