1, monitoring output log interface
/**
*
* Monitor Output Log interface
*/
Public interface Logcatobserver {
/**
*
* @param info
* Output Log information
*/
public void Handlelog (String info);
}
2. Inherit a service
public class Logcatscannerservice extends Service implements Logcatobserver {
Private String IMEI, Simno, Operatorname, Simserialnumber, IMSI, ISO, OSInfo, module, manufacturer, resolution, apps, pack Agename, Versionname,
Versioncode;
Private displaymetrics DM;
Private String sourceidentity = "";//Market identification
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) {
Do this if the uninstall log information is included
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 ("total time = =" + (T3-T1));
SYSTEM.OUT.PRINTLN ("request Network Time = =" + (T3-T2));
}
}
/**
*
* @author monitoring of output log information
*
*/
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 have 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) {
}
}
}
}
/**
* Get user Information
*
*
*/
private void GetUserInfo () {
Telephonymanager TM = (Telephonymanager) getsystemservice (Context.telephony_service);
IMEI = Tm.getdeviceid ();
Simno = Tm.getline1number ();
Operatorname = Tm.getnetworkoperatorname ();
Simserialnumber = Tm.getsimserialnumber ();
IMSI = Tm.getsubscriberid ();
ISO = Tm.getnetworkcountryiso ();
OSInfo = Android.os.Build.VERSION.RELEASE;
module = Android.os.Build.MODEL;
Manufacturer = Android.os.Build.MANUFACTURER;
try {
AppInfo = This.getpackagemanager (). Getapplicationinfo (Getpackagename (), packagemanager.get_meta_data);
Sourceidentity = AppInfo.metaData.get ("Baidumobad_channel"). ToString ();
PackageInfo info = This.getpackagemanager (). Getpackageinfo (This.getpackagename (), 0);
PackageName = Info.packagename;
Versionname = Info.versionname;
Versioncode = Getresources (). getString (r.string.version);
} catch (Namenotfoundexception E1) {
E1.printstacktrace ();
}
try {
Params.put ("Sourceidentity", sourceidentity);
Params.put ("IMEI", IMEI);
Params.put ("Simno", Simno);
Params.put ("Operatorname", operatorname);
Params.put ("Simserialnumber", Simserialnumber);
Params.put ("IMSI", IMSI);
Params.put ("OSInfo", OSInfo);
Params.put ("ISO", ISO);
Params.put ("module", module);
Params.put ("Manufacturer", manufacturer);
Params.put ("Resolution", Resolution);
Params.put ("Apps", apps);
Params.put ("Packageversionname", versionname);
Params.put ("Packageversioncode", Versioncode);
Params.put ("PackageName", PackageName);
Params.put ("Wifimac", deviceinfo.getmacaddress (this));
Params.put ("Bluetoothmac", deviceinfo.getbluetoothaddress (this));
Params.put ("Guiddata", Deviceinfo.filesdirguid (this));
Params.put ("GUIDSD", Deviceinfo.externalstorageguid (this));
System.out.println ("params=" + params.tostring ());
} catch (Jsonexception e) {
E.printstacktrace ();
}
}
/**
* Send data when the user clicks Uninstall
* config is the server URL of the submission
* @return
*/
public boolean dorequest () {
Boolean isrequestok = false;
Jsonobjectrequest jsonobjectrequest = new Jsonobjectrequest (method.post, Config, params,
New Response.listener<jsonobject> () {
@Override
public void Onresponse (Jsonobject arg0) {
System.out.println ("argo=======" + arg0);
}
}, New Response.errorlistener<jsonobject> () {
@Override
public void Onerrorresponse (volleyerror error, Jsonobject Historycache) {
}
});
Mrequestqueue = Volley.newrequestqueue (this);
Mrequestqueue.add (Jsonobjectrequest, this);
Isrequestok = true;
return isrequestok;
}
}
3. Registration Service in Manifest.xml
4. Start the service
StartService (New Intent ("Com.lapel.uninstallservice.LogcatScannerService"));
Monitor App Uninstall operation method Two start service