android实现卸载提示
这篇文章是整理的以前用过的一个功能,由于多种原因现在停用了,也希望这篇文章能帮助一些android入门的小童鞋。android是不提供监控卸载自己的功能的,这里使用了监控android日志的功能,android日志相关知识可以参考《adb logcat 查看日志》这篇文章。
android卸载提示的思路是启动一个服务监控android系统的打印日志,当监控到"android.intent.action.DELETE"并且包含自己应用的包名时,提示给用户。
监控代码
public class AndroidLogcatScannerThread extends Thread {
private LogcatObserver observer;
public AndroidLogcatScannerThread(LogcatObserver observer) {
this.observer = observer;
}
public void run() {
String[] cmds = { "logcat", "-c" };
String shellCmd = "logcat";
Process process = null;
InputStream is = null;
DataInputStream dis = null;
String line = "";
Runtime runtime = Runtime.getRuntime();
try {
observer.handleLog(line);
int waitValue;
waitValue = runtime.exec(cmds).waitFor();
observer.handleLog("waitValue=" + waitValue + "\n Has do Clear logcat cache.");
process = runtime.exec(shellCmd);
is = process.getInputStream();
dis = new DataInputStream(is);
while ((line = dis.readLine()) != null) {
//Log.d("Log","Log.Bestpay:"+line);
if(observer!=null)
observer.handleLog(line);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException ie) {
ie.printStackTrace();
} finally {
try {
if (dis != null) {
dis.close();
}
if (is != null) {
is.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
监控服务:
public class AndroidLogcatScannerService extends Service implements LogcatObserver{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
AndroidLogcatScannerThread scannerThread=new AndroidLogcatScannerThread(AndroidLogcatScannerService.this);
scannerThread.start();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void handleLog(String info) {
// TODO Auto-generated method stub
if (info.contains("android.intent.action.DELETE") && info.contains(getPackageName())) {
Intent intent = new Intent();
intent.setClass(AndroidLogcatScannerService.this, UninstallActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
上面的代码基本实现了卸载提示,最后不要忘了权限:
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
代码下载地址:
http://download.csdn.net/detail/xyz_lmn/4904797
android实现卸载提示的更多相关文章
- Android之hint提示字体大小修改,显示完全
Android之hint提示字体大小修改,显示完全 1.工作中遇到一个问题,就是自定义EditText的hint提示在超大字体下会显示不全, 2.然后在网上搜索了一下,在这里记录一下,分享给大家,在此 ...
- android中的提示信息显示方法(toast应用)
android中的提示信息显示方法(toast应用) (2011-10-17 11:02:06) 转载▼ 标签: android toast 杂谈 分类: Android android中toast的 ...
- Android Studio中提示:Project SDK is not defined
Android Studio中提示:Project SDK is not defined 2015 年 4 月 1 日 下午 9:04crifan已有2209人围观我来说几句 [背景] 之前用Andr ...
- 错误异常 (1)Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) will not work properly
[已解决]Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) wil ...
- Xamarin Android设置界面提示类型错误
Xamarin Android设置界面提示类型错误 错误信息:Integer types not allow (at ‘padding’ with value ’10’)Android界面属性的长度和 ...
- INNO:检测程序是否已经安装,是则弹出卸载提示。
INNO:检测程序是否已经安装,是则弹出卸载提示. 作者:少轻狂 | 发布:2010-08-05 | 更新:2013-09-05 | 分类:部署 | Disposition | 热度:2816 ℃ 实 ...
- 第13讲- Android之消息提示Notification
第13讲 Android之消息提示Notification .Notification Notification可以理解为通知的意思一般用来显示广播信息,通知可以显示到系统的上方的状态栏(status ...
- 第12讲- Android之消息提示Toast
第12讲 Android之消息提示Toast .Toast Toast 是一个 View 视图,在应用程序上浮动显示少量的信息给用户,它永远不会获得焦点,不影响用户的输入等操作,主要用于向用户显示一些 ...
- Android 模式对话框提示Dialog
1.先写一个Dialog类 CustomDialog package com.example.heng.adtest; import android.app.AlertDialog; import ...
随机推荐
- POJ 2942 Knights of the Round Table 黑白着色+点双连通分量
题目来源:POJ 2942 Knights of the Round Table 题意:统计多个个骑士不能參加随意一场会议 每场会议必须至少三个人 排成一个圈 而且相邻的人不能有矛盾 题目给出若干个条 ...
- 用unity3d切割图片
原地址:http://www.cnblogs.com/leng-yuye/archive/2012/05/31/2528148.html 需求:把图片的像素中不为alpha的部分切出来保存成单个图片. ...
- linux 终端分屏命令vsp(转)
比如:某文件夹下有文件:vector.cc, substr.cc 1.使用vim命令打开任意一个文件:vim vector.cc打开第一个文件.如下图所示: 2.按:"Esc"键 ...
- 如何在谷歌浏览器中查看Axure做的原型HTML
Axure RP Pro可谓是非常方便.好用的一款软件,因为它不仅能绘制出详细的产品构思,也能生成浏览器格式的产品原型.但如果想把原型拿给客户查看,需要看产品画的原型图时,但是打不开的话就悲剧了.经常 ...
- sql笔记 获取指定数据库下的所有表
SELECT Name FROM 数据库名称..SysObjects Where XType='U' ORDER BY Name XType='U' 标识查询用户创建的表 S为系统创建的表
- 转用Jmeter测试RabbitMQ
转自:https://blog.csdn.net/luozhuwang/article/details/62044872 1.下载AMQP插件 github上面有源码,可以通过ant+ivy在本地进行 ...
- Android模拟器Genymotion安装apk
一.下载apk 选择你需要安装的apk进行下载,下载完以后放在与adb.exe同一目录下: 看我的 二.安装apk遇到的问题 开启Genymotion模拟器,然后cmd到你的platform-tool ...
- AIX下RAC搭建 Oracle10G(六)dbca建库
AIX下RAC搭建系列 AIX下RAC搭建 Oracle10G(六)dbca建库 环境 节点 节点1 节点2 小机型号 IBM P-series 630 IBM P-series 630 主机名 AI ...
- C#微信公众号学习 - (一)测试账号申请
主要分为两部分: 1.创建C#的项目,并发布, 2.微信填写发布的地址进行开发者验证. 一. VS环境为VS2017,创建项目时,自带的一些东西发布会导致各种错误,无奈,创建了空项目aspx窗体,如下 ...
- C++在线编译器
主要有3个,且它们都支持C++11 http://gcc.godbolt.org/ http://coliru.stacked-crooked.com/ http://ideone.com/ 第一个网 ...