gpt4 book ai didi

java - 不兼容的类型。必需 : android. content.Context 找到 : java. lang.String

转载 作者:行者123 更新时间:2023-12-02 04:45:35 25 4
gpt4 key购买 nike

我需要使用 Secure.getString() 获取设备 ID

我正在使用上下文

 public static String getDeviceId(Context context) {
String currentDeviceId = SharedPreferencesUtil.getCurrentDeviceId();
if (currentDeviceId == null) {
context = Secure.getString(context.getContentResolver(), "android_id");
if (context == null || context.trim().isEmpty() || "9774d56d682e549c".equalsIgnoreCase(context)) {
context = Build.SERIAL;
if (context == null || context.trim().isEmpty() != null) {
context = UUID.randomUUID().toString();
} else {
context = Build.SERIAL;
}
}
if ("unknown".equals(context)) {
context = Build.SERIAL;
if (context == null || context.trim().isEmpty() != null) {
context = UUID.randomUUID().toString();
} else {
context = Build.SERIAL;
}
}
secondDeviceId = context;

此行显示以下错误

context = Secure.getString(context.getContentResolver(), "android_id");

Incompatible types. Required: android.content.Context Found: java.lang.String

最佳答案

根据 @vlumi 评论和我的调试,我发现以下代码可以解决此问题。现在已修复,只需将 context 替换为字符串即可。

public static String getDeviceId(Context paramContext) {
String localObject = SharedPreferencesUtil.getCurrentDeviceId();
if (localObject == null) {
String str1 = Settings.Secure.getString(paramContext.getContentResolver(), "android_id");
if ((str1 == null) || (str1.trim().isEmpty()) || ("9774d56d682e549c".equalsIgnoreCase(str1)))
{
String str2 = Build.SERIAL;
if ((str2 != null) && (!str2.trim().isEmpty())) {
str1 = Build.SERIAL;
} else {
str1 = UUID.randomUUID().toString();
}
}
if ("unknown".equals(str1))
{
String str3 = Build.SERIAL;
if ((str3 != null) && (!str3.trim().isEmpty())) {
str1 = Build.SERIAL;
} else {
str1 = UUID.randomUUID().toString();
}
}
secondDeviceId = str1;

关于java - 不兼容的类型。必需 : android. content.Context 找到 : java. lang.String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56486567/

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