我在Google Play上有两个应用。新旧的。我想对新应用使用旧的身份验证令牌,以使用户更轻松。
我尝试使用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.
}
})
}
答案 0 :(得分:2)
对于用户来说,这听起来不错,但似乎非常危险。您正在发送一个Auth令牌-如果有人拥有Auth令牌,则该令牌可以允许他们通过不受信任的系统(例如世界可读文件或URL中的引用参数)以该用户的任何身份登录。
如果您确实需要这样做,建议您在安装应用程序后使用某种形式的应用程序间RPC(IPC)来传达令牌。一种选择是向提供身份验证的服务a binder。