您的位置:首页 > 移动开发

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服务启动");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: