EMALLStudio / appmetrica_sdk

A Flutter plugin for Yandex AppMetrica SDK, a marketing platform for app install attribution, app analytics, and push campaigns.
https://pub.dev/packages/appmetrica_sdk
Other
15 stars 22 forks source link

No GetDeviceId getter #12

Open ak1987 opened 3 years ago

ak1987 commented 3 years ago

I didn't found appDeviceId getter method. I've never worked with Java language, so don't blame code quality. My workaround was:

private void handleGetDeviceId(MethodCall call, Result result) {
        try {
            System.out.println("Getting DeviceID");
            final String[] deviceId = new String[1];
            AppMetricaDeviceIDListener listener = new AppMetricaDeviceIDListener() {
                @Override
                public void onLoaded(@Nullable String s) {
                    deviceId[0] = s;
                    System.out.println("s loaded: " + s);
                    System.out.println("deviceId[0] set: " + deviceId[0]);
                }

                @Override
                public void onError(@NonNull AppMetricaDeviceIDListener.Reason reason) {
                    System.out.println("DeviceID loading error");
                }
            };
            YandexMetrica.requestAppMetricaDeviceID(listener);
            TimeUnit.SECONDS.sleep(1);
            System.out.println("deviceId[0] loaded: " + deviceId[0]);
            result.success(deviceId[0]);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
            result.error("Error getting Device ID", e.getMessage(), null);
        }
    }

It worked. Please fell free to take it as a starting point.