private void unregisterApps(Set<String> apps) { Set<String> unregisteringApps = ApeicPrefsUtil.getInstance(this).getStringSetPref(ApeicPrefsUtil.KEY_UNREGISTERING_APPS); for (String app : apps) { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet( API_PREFIX + "/" + ApeicPrefsUtil.getInstance(this).getAndroidID() + "/" + SUFFIX_UNREGISTER + "?app=" + app); try { HttpResponse response = client.execute(get); int statusCode = response.getStatusLine().getStatusCode(); Log.d( ApeicUtil.TAG_HTTP, "Status code of unregistering " + app + ": " + String.valueOf(statusCode)); if (statusCode == 200) { if (unregisteringApps.contains(app)) { unregisteringApps.remove(app); } } else { unregisteringApps.add(app); } } catch (IOException e) { Log.e(ApeicUtil.TAG_HTTP, e.getMessage()); unregisteringApps.add(app); } } ApeicPrefsUtil.getInstance(this) .setStringSetPref(ApeicPrefsUtil.KEY_UNREGISTERING_APPS, unregisteringApps); }
@Override protected void onHandleIntent(Intent intent) { Log.v(ApeicUtil.TAG_HTTP, "UpdateInstalledAppsIntentService onHandleIntent"); PackageManager pm = getPackageManager(); Set<String> currInstalledApps = new HashSet<String>(); for (ApplicationInfo info : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { if (pm.getLaunchIntentForPackage(info.packageName) != null) { currInstalledApps.add(info.packageName); } } ApeicPrefsUtil prefsUtil = ApeicPrefsUtil.getInstance(this); Set<String> registeringApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS); if (registeringApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Re-update newly installed apps."); registerApps(prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS)); } Set<String> unregisteringApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS); if (unregisteringApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Re-update uninstalled installed apps."); unregisterApps(prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_UNREGISTERING_APPS)); } if (prefsUtil.getPrefs().contains(ApeicPrefsUtil.KEY_INSTALLED_APPS)) { Set<String> lastInstalledApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_INSTALLED_APPS); Set<String> newlyInstalledApps = getNewlyInstalledApps(currInstalledApps, lastInstalledApps); if (newlyInstalledApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Newly installed Apps: "); registerApps(newlyInstalledApps); } Set<String> removedApps = getUninstalledApps(currInstalledApps, lastInstalledApps); if (removedApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Uninstalled Apps: "); unregisterApps(removedApps); } } else { Log.v(ApeicUtil.TAG_HTTP, "Current installed Apps: "); registerApps(currInstalledApps); } ApeicPrefsUtil.getInstance(this) .setStringSetPref(ApeicPrefsUtil.KEY_INSTALLED_APPS, currInstalledApps); }
private String getUploadUrl() { return API_PREFIX + "/" + ApeicPrefsUtil.getInstance(this).getAndroidID() + "/" + SUFFIX_UPLOAD; }