gpt4 book ai didi

java - 从该应用程序访问该应用程序的安装量

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:52 27 4
gpt4 key购买 nike

是否可以从该应用程序获取该应用程序的确切安装量?我想“奖励”前 100 名下载我的应用程序的人。

我可以自己做,使用一个数据库,每次有人第一次启动应用程序时该数据库都会递增,但我想知道类似的东西是否已经存在,但到目前为止我没有找到任何东西。

最佳答案

完成!我尝试了 Parse,但它似乎没有任何结果,所以我决定使用远程数据库。

我对 PHP 和连接到远程服务器有点陌生,所以可能会出现一些错误。但到目前为止,它已经完成了工作,尽管有时会卡住,而且除了关闭应用程序之外没有办法摆脱它。我不知道这是否是我犯的错误,或者是因为我使用廉价且可能不稳定的服务器来测试它。不过,请随时提出您可以想到的任何改进建议。

安卓:

@Override
public boolean isFirst1000() {
byte[] data;
HttpPost httppost;
StringBuffer buffer = new StringBuffer();
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;

try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost(
"http://jaimebeaucouplepain.com/first1000.php");

response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();

data = new byte[256];

buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}

inputStream.close();
}

catch (Exception e) {
return false;
}

String str = buffer.toString();

if (str.contains("first1000yes")) {
return true; // The user is one of the first 1000. We don't have to check again.
}
else if (str.contains("first1000no")) {
return false; // The user is not one of the first 1000. We don't have to check again.
}
else {
return false; // There was an error with the server. We will have to check again (next time the user launches the app for example).
}
}

PHP:

<?php

require("config.inc.php");

try {
$result = $db->query("SELECT COUNT(*) FROM first1000");
$row = $result->fetch();
$nbUsers = $row["COUNT(*)"];
}
catch (PDOException $ex) {
$response = "Database Error.";
die(json_encode($response));
}

if ($nbUsers < 1000) {
$query = "INSERT INTO first1000 (id) VALUES (DEFAULT)";

try {
$stmt = $db->prepare($query);
$result = $stmt->execute();
}
catch (PDOException $ex) {
$response = "Database Error.";
die(json_encode($response));
}

$response = first1000yes;
echo $nbUsers;
echo json_encode($response);
}
else {
$response = first1000no;
echo json_encode($response);
}

?>

这是它的工作原理。每次玩家第一次启动应用程序时,我们都会检查数据库。如果已经有 1000 个条目,则意味着当前用户不是前 1000 个用户,因此不应获得奖励。否则,我们会添加一个条目并奖励玩家。然后,我们确保不会在每次玩家启动应用程序时进行检查,因为玩家数量不会随着时间的推移而减少。完成后,我们可以使用 prefs.putBoolean("checkFirst1000", true) 这样的首选项。

如果过程中出现错误(例如没有互联网),我们将无法奖励玩家。但我们不会调用 prefs.putBoolean("checkFirst1000", true) 因为我们想下次检查,并且每次都检查,直到我们确定玩家是否是前 1000 名玩家之一。

关于java - 从该应用程序访问该应用程序的安装量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29521166/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com