Несовместимые типы. Требуется: android.content.Context Найдено: java.lang.String - PullRequest
0 голосов
/ 07 июня 2019

Мне нужно получить идентификатор устройства с помощью Secure.getString ()

Я использую контекст

 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");

Несовместимые типы.Требуется: android.content.Context Найдено: java.lang.String

1 Ответ

0 голосов
/ 07 июня 2019

Согласно комментарию @vlumi и моей отладке, я нашел следующий код, чтобы это исправить. Это исправлено сейчас, просто нужно заменить контекст на строку.

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;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...