question

ene avatar image
ene asked

Playing as Guest

I tried making player register playing as guest and get the androiddeviceid but i got this error. I tried to click the red warning and it take me to this code

AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject>("getContentResolver");

Here is my full code https://pastebin.com/upA6bvKg

adlztin0vb.png (24.4 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ene avatar image ene commented ·

I was watching this vid for tutorial, i tried what u said and build the .apk file and install it on emulator. I can create a guest account and have android icon beside it. Is there no other way to make it work on Unity Editor for example if i want to debug my code to see if my code is wrong or not ?

0 Likes 0 ·

1 Answer

·
JayZuo avatar image
JayZuo answered

This code should only be run on Android devices. While using in Editor, you may get these error. So you can not comment out "&& !UNITY_EDITOR". And if you want to test, you will need to test it with Android device or emulator.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ene avatar image ene commented ·

Thankyou for the advice

1 Like 1 ·
ene avatar image ene commented ·

I was watching this vid for tutorial, i tried what u said and build the .apk file and install it on emulator. I can create a guest account and have android icon beside it. Is there no other way to make it work on Unity Editor for example if i want to debug my code to see if my code is wrong or not ?

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ ene commented ·

If you do want to test in Editor, you can just give a fake "deviceId" instead of getting the device id from native android.

0 Likes 0 ·
Justin avatar image Justin ene commented ·

Like Jay Zuo said here is an example of what we are doing there:

private void LoginWithDeviceID(bool createAccount)

{

// NOTE: This sets the origination for the player (android, ios, pc)

// true: creates new a PlayfabID linked to this DeviceID

// false: checks to see if DeviceID has been linked to a PlayfabID already.

#if UNITY_ANDROID && UNITY_EDITOR // For Unity Editor Android Platform

android_id = SystemInfo.deviceUniqueIdentifier; Debug.Log("LoginWithAndroidDeviceID, UNITY_EDITOR");

#elif UNITY_ANDROID && !UNITY_EDITOR // For Android device

android_id = AndroidIdRetriever.Retrieve(); // --> SystemInfo.deviceUniqueIdentifier <-- Not recommended on android

Debug.Log("LoginWithAndroidDeviceID, UNITY_ANDROID");

#endif

#if UNITY_ANDROID // Android device or Editor with Android Platform

PlayFabClientAPI.LoginWithAndroidDeviceID(new LoginWithAndroidDeviceIDRequest()

{

TitleId = PlayFabSettings.TitleId,

AndroidDevice = SystemInfo.deviceModel,

OS = SystemInfo.operatingSystem,

AndroidDeviceId = android_id,

CreateAccount = createAccount,

}, OnLoginWithDeviceIDSuccess, OnPlayFabError);

#endif

}

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.