简体   繁体   中英

Android application install/uninstall event

There is an application and it needs system reboot after installation. I registrered boot receiver and write info to system log. And activity checks for this line. It works well, but there is one problem...

When user uninstall and install this app in one session(I mean user doesn't reboot phone) system log still has line "Phone restarted" and application runs with errors.

As I know I can't check uninstallation event on my app cause receiver stops before the application going to uninstall. So my question is could I check for my app installation? or maybe uninstallation any other way?

Thanks!

Maybe someone will be interested. I found the code that allows me to checked system reboot after installation/update:

public static boolean phone_rebooted(Context ctx) {
        ApplicationInfo appInfo = ctx.getApplicationInfo();
        String appFile = appInfo.sourceDir;
        long installed = new File(appFile).lastModified();

        long boot_time = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        if(boot_time < installed) {
           return false;
        } else {
           return true;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM