app卸载后弹出页面-方法2(java+log日志信息)
2015-01-22 17:17
330 查看
1、
/**
*
* @author dingqb 监控输出日志接口
*/
public interface LogcatObserver {
/**
*
* @param info
* 输出的日志信息
*/
public void handleLog(String info);
}
2、
public class LogcatScannerService extends Service implements LogcatObserver {
private String iMEI, simNo, operatorName, simSerialNumber, iMSI, iSO, oSInfo, module, manufacturer, resolution, apps, packageName, versionName,
versionCode;
private DisplayMetrics dm;
private String SourceIdentity = "";// 市场标识
ApplicationInfo appInfo;
private RequestQueue mRequestQueue;
JSONObject params = new JSONObject();
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
new AndroidLogcatScannerThread(this).start();
getUserInfo();
}
@Override
public void handleLog(String info) {
// 如果包含了卸载日志信息时就执行此操作
if (info.contains("android.intent.action.DELETE") && info.contains(getPackageName())) {
long t1 = System.currentTimeMillis();
// getUserInfo();
long t2 = System.currentTimeMillis();
doRequest();
long t3 = System.currentTimeMillis();
System.out.println("总时间==" + (t3 - t1));
System.out.println("请求网络时间==" + (t3 - t2));
}
}
/**
*
* @author 实现输出日志信息的监控
*
*/
private class AndroidLogcatScannerThread extends Thread {
private LogcatObserver mObserver;
public AndroidLogcatScannerThread(LogcatObserver observer) {
mObserver = observer;
}
@Override
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 {
mObserver.handleLog(line);
int waitValue;
waitValue = runtime.exec(cmds).waitFor();
mObserver.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) {
if (mObserver != null)
mObserver.handleLog(line);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException ie) {
} finally {
try {
if (dis != null) {
dis.close();
}
if (is != null) {
is.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
}
}
}
}
}
3、
<!-- 注册卸载时启动的服务 -->
<service android:name="xxxxxxxxx.LogcatScannerService" >
<intent-filter>
<action android:name="xxxxxxxxx.LogcatScannerService" />
</intent-filter>
</service>
4、 startService(new Intent("com.lapel.uninstallservice.LogcatScannerService"));
System.out.println("监听卸载app服务启动");
/**
*
* @author dingqb 监控输出日志接口
*/
public interface LogcatObserver {
/**
*
* @param info
* 输出的日志信息
*/
public void handleLog(String info);
}
2、
public class LogcatScannerService extends Service implements LogcatObserver {
private String iMEI, simNo, operatorName, simSerialNumber, iMSI, iSO, oSInfo, module, manufacturer, resolution, apps, packageName, versionName,
versionCode;
private DisplayMetrics dm;
private String SourceIdentity = "";// 市场标识
ApplicationInfo appInfo;
private RequestQueue mRequestQueue;
JSONObject params = new JSONObject();
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
new AndroidLogcatScannerThread(this).start();
getUserInfo();
}
@Override
public void handleLog(String info) {
// 如果包含了卸载日志信息时就执行此操作
if (info.contains("android.intent.action.DELETE") && info.contains(getPackageName())) {
long t1 = System.currentTimeMillis();
// getUserInfo();
long t2 = System.currentTimeMillis();
doRequest();
long t3 = System.currentTimeMillis();
System.out.println("总时间==" + (t3 - t1));
System.out.println("请求网络时间==" + (t3 - t2));
}
}
/**
*
* @author 实现输出日志信息的监控
*
*/
private class AndroidLogcatScannerThread extends Thread {
private LogcatObserver mObserver;
public AndroidLogcatScannerThread(LogcatObserver observer) {
mObserver = observer;
}
@Override
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 {
mObserver.handleLog(line);
int waitValue;
waitValue = runtime.exec(cmds).waitFor();
mObserver.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) {
if (mObserver != null)
mObserver.handleLog(line);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException ie) {
} finally {
try {
if (dis != null) {
dis.close();
}
if (is != null) {
is.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
}
}
}
}
}
3、
<!-- 注册卸载时启动的服务 -->
<service android:name="xxxxxxxxx.LogcatScannerService" >
<intent-filter>
<action android:name="xxxxxxxxx.LogcatScannerService" />
</intent-filter>
</service>
4、 startService(new Intent("com.lapel.uninstallservice.LogcatScannerService"));
System.out.println("监听卸载app服务启动");
相关文章推荐
- app卸载后弹出页面-方法1(NDK+C)
- java得到距离指定时间num时间的时间、以及反射调用方法、Log日志配置信息
- 一种弹出提示信息时页面背景色调改变的方法
- java日志信息 log4j 使用方法
- java获取redis日志信息与动态监控信息的方法
- 嵌入APP的H5页面点击时不需要弹出app键盘的方法
- java日志信息 log4j 使用方法 【转】
- 详解Android App卸载后跳转到指定的反馈页面的方法
- rest-assured 将log()中的信息打印到log日志中去的方法
- Android学习第三篇;在java,c++,c中用日志方法打印信息
- java日志信息 log4j 使用方法
- JAVA方法耗时信息捕捉并日志
- 关于android studio log日志打印信息不全的原因以及解决方法
- 让背景如此暗淡(一种弹出提示信息时页面背景色调改变的方法)
- java日志信息 log4j 使用方法
- 【ios自学笔记】OC中log信息的输出方法,包含import、字符串、输出日志等知识点
- java---使用日志输出信息的方法
- 非常漂亮的让背景如此暗淡(一种弹出提示信息时页面背景色调改变的方法)
- Java log日志的配置方法(MyEclipse10)
- 非常漂亮的让背景如此暗淡(一种弹出提示信息时页面背景色调改变的方法)