我在 Google Play 上有两个应用程序。旧的和新的。我想在新应用程序中使用旧的身份验证 token ,以便用户更方便。
- 在旧应用中,用户会看到一个弹出窗口,用于在 Google Play 上安装新应用。
- 我想将参数中的身份验证 token 传递给 Google Play。
- 安装新应用后,我想将 token 保存在新应用中。
我尝试使用 Play Install Referrer Library但没有成功。
另一种方法是使用 SharedPreferences
,但 MODE_WORLD_READABLE
已被弃用。
旧应用程序:
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.<PACKAGENAME>&token=pokpok&refresh_token=lolol"));
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.<PACKAGENAME>?token=pokpok&refresh_token=lolol")));
}
新APP代码:
private fun shouldGetTokenFromOldApp() {
mReferrerClient = InstallReferrerClient.newBuilder(this).build()
mReferrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
// Connection established
val response: ReferrerDetails = mReferrerClient.installReferrer
val url = "https://play.google.com/store?${response.installReferrer}"
Log.d("APP", "Token old app 1 : $url")
val uri: Uri = Uri.parse(url)
val token = uri.getQueryParameter("token")
val refreshToken = uri.getQueryParameter("refresh_token")
Log.d("APP", "Token old app 2 : $token - $refreshToken")
mReferrerClient.endConnection()
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
// API not available on the current Play Store app
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
// Connection could not be established
}
}
}
override fun onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
}
最佳答案
这听起来对用户来说是一件好事,但似乎非常危险。您正在发送一个身份验证 token - 如果有人拥有该 token ,则可以允许他们通过不可信的系统(例如世界可读文件或 URL 中的引用参数)以该用户身份在任何地方登录。
如果您确实需要这样做,我建议在安装应用程序后使用某种形式的应用程序间 RPC (IPC) 来传递 token 。一种选择是 a binder提供身份验证的服务。
关于java - 使用旧身份验证 token 将用户迁移到新应用程序 - InstallReferrer 自定义参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51177024/