下载事件统计,添加该游戏已安装数
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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("插件化")) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user