下载事件统计,添加该游戏已安装数

This commit is contained in:
huangzhuanghua
2016-10-28 11:23:42 +08:00
parent 54df9912eb
commit 11abd6d60f
4 changed files with 32 additions and 10 deletions

View File

@ -26,14 +26,12 @@ public class TrafficUtils {
synchronized (TrafficUtils.class) {
if (instance == null) {
instance = new TrafficUtils(context);
if (update)
instance.update();
return instance;
}
}
}
if (update)
if (update) {
instance.update();
}
return instance;
}
@ -47,9 +45,7 @@ public class TrafficUtils {
// 获取所有的安装在手机上的应用软件的信息,并且获取这些软件里面的权限信息
PackageManager pm = context.getPackageManager();// 获取系统应用包管理
// 获取每个包内的androidmanifest.xml信息它的权限等等
List<PackageInfo> pinfos = pm
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_PERMISSIONS);
List<PackageInfo> pinfos = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
// 遍历每个应用包信息
for (PackageInfo info : pinfos) {
// 请求每个程序包对应的androidManifest.xml里面的权限
@ -64,9 +60,7 @@ public class TrafficUtils {
long rx = TrafficStats.getUidRxBytes(uId);
// 如果返回-1代表不支持使用该方法注意必须是2.2以上的
long tx = TrafficStats.getUidTxBytes(uId);
if (rx < 0 || tx < 0) {
continue;
} else {
if (rx >= 0 && tx >= 0) {
db.update(info.packageName, rx + tx);
}
}

View File

@ -262,6 +262,24 @@ public class DownloadEntity implements Serializable {
meta.put("end", String.valueOf(end));
}
public long getInstalled() {
if (meta != null) {
String installed = meta.get("installed");
if (installed == null) {
return 0;
}
return Integer.valueOf(installed);
}
return 0;
}
public void setInstalled(int installed) {
if (meta == null) {
meta = new HashMap<>();
}
meta.put("installed", String.valueOf(installed));
}
public HashMap<String, String> getMeta() {
return meta;
}

View File

@ -10,9 +10,11 @@ import android.widget.Toast;
import com.gh.common.constant.Constants;
import com.gh.common.util.FileUtils;
import com.gh.common.util.MD5Utils;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.Utils;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.manager.PackageManager;
import java.io.File;
import java.util.ArrayList;
@ -226,6 +228,13 @@ public class DownloadManager {
downloadEntity.setGameId(gameEntity.getId());
downloadEntity.setEntrance(entrance);
downloadEntity.setLocation(location);
int installed = 0;
for (ApkEntity apk : gameEntity.getApk()) {
if (PackageManager.isInstalled(apk.getPackageName())) {
installed++;
}
}
downloadEntity.setInstalled(installed);
if (method.equals("更新")) {
downloadEntity.setUpdate(true);
} else if (method.equals("插件化")) {

View File

@ -261,6 +261,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
map.put("status", "完成");
map.put("entrance", downloadEntity.getEntrance());
map.put("location", downloadEntity.getLocation());
map.put("installed", downloadEntity.getInstalled());
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
DataCollectionManager.onEvent(MainActivity.this, "download", map);
}