user can't log into google play services - c#

User authentication doesn't work in my app that I'm making for android. This is the script that is attached to an empty game object in my main menu.
void Start()
{
PlayGamesPlatform.Activate();
PlayGamesPlatform.DebugLogEnabled = true;
}
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
public void showleaderboard()
{
if(Social.localUser.authenticated)
{
PlayGamesPlatform.Instance.ShowLeaderboardUI("CgkIq82p4qcNEAIQAQ");
}
else
{
Debug.Log("leaderboard not working");
}
}
public void userlogin()
{
Social.localUser.Authenticate((bool success) =>
{
if(success)
{
Debug.Log("Logged in");
}
else
{
Debug.Log("Login failed");
}
});
}
The functions are attached to buttons and I always get the log "Login Failed" in my console. I tested this on an android device that was able to log into google play services in other published apps.

You should add your account as test account in Google play services panel, otherwise it will be always a failed login.

Related

Unity ads don't work; they won't appear on my screen

I just finished a tiny game and I wanted to learn how to implement ads, for fun. I won't post the game. I did what Unity was saying, I finished the monetization and I made a game object called Ads (I did put "andriod ID" and "iOS ID") with the following code:
using UnityEngine;
using UnityEngine.Advertisements;
public class InterstitialAdExample : MonoBehaviour, IUnityAdsLoadListener,
IUnityAdsShowListener
{
[SerializeField] string _androidAdUnitId = "Interstitial_Android";
[SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
string _adUnitId;
void Awake()
{
// Get the Ad Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
}
// Load content to the Ad Unit:
public void LoadAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
// Show the loaded content in the Ad Unit:
public void ShowAd()
{
// Note that if the ad content wasn't previously loaded, this method will fail
Debug.Log("Showing Ad: " + _adUnitId);
Advertisement.Show(_adUnitId, this);
}
// Implement Load Listener and Show Listener interface methods:
public void OnUnityAdsAdLoaded(string adUnitId)
{
// Optionally execute code if the Ad Unit successfully loads content.
}
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
// Optionally execute code if the Ad Unit fails to load, such as attempting to try again.
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Optionally execute code if the Ad Unit fails to show, such as loading another ad.
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) { }
}
I don't get any errors, but the ads don't appear and I am stuck. Does anyone have any ideas?
You can try the following steps:
1.Turn on the advertising service in the project settings, as shown in the figure.
2.Import the Advertisement package in the package manager.
3.In the build settings, set the export platform to Android platform.
Add two buttons to the scene, one to load the ad and one to display the ad.
Create a new script AdsInitializer and mount it on the camera.
[SerializeField] string _androidGameId;
[SerializeField] string _iOsGameId;
[SerializeField] bool _testMode = true;
[SerializeField] bool _enablePerPlacementMode = true;
private string _gameId;
void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode, _enablePerPlacementMode, this);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
Create a new script RewardedAdsButton, which is also mounted on the camera, specify _showAdButton as the button to display the advertisement, and add the LoadAd() method in the RewardedAdsButton script to the button to load the advertisement.
void Awake()
{
// Get the Ad Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
//Disable button until ad is ready to show
_showAdButton.interactable = false;
}
// Load content to the Ad Unit:
public void LoadAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
// If the ad successfully loads, add a listener to the button and enable it:
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log("Ad Loaded: " + adUnitId);
if (adUnitId.Equals(_adUnitId))
{
// Configure the button to call the ShowAd() method when clicked:
_showAdButton.onClick.AddListener(ShowAd);
// Enable the button for users to click:
_showAdButton.interactable = true;
}
}
// Implement a method to execute when the user clicks the button.
public void ShowAd()
{
// Disable the button:
_showAdButton.interactable = false;
// Then show the ad:
Advertisement.Show(_adUnitId, this);
}
// Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
// Implement Load and Show Listener error callbacks:
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Use the error details to determine whether to try to load another ad.
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Use the error details to determine whether to try to load another ad.
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
void OnDestroy()
{
// Clean up the button listeners:
_showAdButton.onClick.RemoveAllListeners();
}
Get the game ID of Android and iOS, and click Dashboard in the service page of the project settings.
After the webpage is opened, click Monetization => ad Units to see the game IDs of Android and Apple, you need to enable them yourself.
Go back to Unity and enter the queried id in the AdsInitializer script on the camera.
Packaged into the Android emulator to run.

Ads are working In Editor but not In Android

I am trying to use ads In my game . They are properly working in Unity but not in Android. Because of I am using unity 2018.4.25f1 personal so it's supporting older version of unity monetization asset. Maybe it's a problem but here is my code of Rewarded Video CSharp file
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
[RequireComponent(typeof(Button))]
public class RewardedVideo : MonoBehaviour, IUnityAdsListener
{
#if UNITY_IOS
private string gameId = "3853032";
#elif UNITY_ANDROID
private string gameId = "3853033";
#endif
[SerializeField]Button myButton;
[SerializeField]GameObject errorMessage;
public string myPlacementId = "rewardedVideo";
void Start()
{
// Map the ShowRewardedVideo function to the button’s click listener:
if (myButton)
myButton.onClick.AddListener(ShowRewardedVideo);
// Initialize the Ads listener and service:
Advertisement.AddListener(this);
Advertisement.Initialize(gameId, true);
}
public void okError()
{
errorMessage.SetActive(false);
}
// Implement a function for showing a rewarded video ad:
public void ShowRewardedVideo()
{
if(Advertisement.IsReady() == true)
Advertisement.Show(myPlacementId);
else
errorMessage.SetActive(true);
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsReady(string placementId)
{
// If the ready Placement is rewarded, activate the button:
if (placementId == myPlacementId)
{
// myButton.interactable = true;
}
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
int levels = PlayerPrefs.GetInt("unlockedLevel", 1);
if(levels != 5)
{
PlayerPrefs.SetInt("unlockedLevel", levels+1);
}
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
}
else if (showResult == ShowResult.Failed)
{
Debug.LogError("The ad did not finish due to an error");
}
}
public void OnUnityAdsDidError(string message)
{
// Log the error.
}
public void OnUnityAdsDidStart(string placementId)
{
// Optional actions to take when the end-users triggers an ad.
}
}
Downloaded asset from Assets store not from package manager. I saw Unity help, unity forum, stackoverflow but nothing solved my problem
Have you any suggestion?

Xamarin Audio players not working in Galaxy S8

I am trying to get a shoutcast URL (.stream) to stream audio in a cross-platform application. I've started with the Android app first and I cannot get the audio playing on the test device Samsung Galaxy S8.
However, the audio players work fine within the Emulator. If it weren't for the test device I would've assumed everything was working.
I've tried using "the local MediaPlayer" and "Plugin.MediaManager": Both work in the Emulator but none on the device. I have enabled the permissions required in the manifest: ACCESS_NETWORK_STATE, INTERNET, MEDIA_CONTENT_CONTROLS, RECORD_AUDIO, WAKE_LOCK, READ_EXTERNAL_STORAGE
(using MediaManager plugin)
in MainActivy:
protected override void OnCreate(Bundle savedInstanceState)
{
.....
CrossMediaManager.Current.Init(this);
.....
}
public class StreamingService: IStreaming.IStreaming
{
bool IsPrepared = false;
public async void Play()
{
await CrossMediaManager.Current.Play("http://someUrl/stream");
}
public void Pause()
{
CrossMediaManager.Current.Pause();
}
public void Stop()
{
CrossMediaManager.Current.Stop();
IsPrepared = false;
}
public int getResponse()
{
if (CrossMediaManager.Current.IsPlaying())
return 1;
else
return 0;
}
}
If I look at the data usage for the app on the device it is set to 0kb after a few tries it goes up by the kb currently at 3.24kb data usage. It doesnt appear that the media player is trying to access the stream, or can even access the stream.
I found a nuget package: LibVLCSharp.Forms
in the Main application created a class:
using LibVLCSharp.Shared;
public class RadioStream
{
readonly LibVLC _libVLC;
readonly MediaPlayer _mp;
public RadioStream()
{
if (DesignMode.IsDesignModeEnabled) return;
Core.Initialize();
_libVLC = new LibVLC();
_mp = new MediaPlayer(_libVLC);
}
public void Init()
{
_mp.Media = new Media(_libVLC, "http://url/stream", FromType.FromLocation);
_mp.Media.AddOption(":no-video");
}
public void Play(bool play)
{
if (play)
_mp.Play();
else _mp.Pause();
}
public bool isPlaying()
{
if (_mp.IsPlaying == false)
return false;
else
return true;
}
}
And its working!
In a while loop I check the isPlaying() that allows me to set the status of the stream and display accordingly.
Its simple at the moment, and stops playing when the internet state changes. But the above is working for simple playback.

Unity Facebook login not works on Facebook App in the Android device

So i implemented Facebook SDK in my project, here the problem is FBlogin not works when i have facebook app in my android device. Please my and my team stuck in this stuff. For more details please replay to this post.
Here is the Code of my Facebook. It is working great when i uninstall facebook app in my device.
With facebook app in my android device : When open my game, facebook window is appear like do you want to continue insted of Login ask, when i click continue its not fetching my details like "Name and Profile Pic"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
using Facebook.MiniJSON;
using UnityEngine.UI;
using System.IO;
using System;
public class Login : MonoBehaviour
{
public string fbname;
public string get_data;
public InputField login_name;
public Image profilePic;
public Text fbNameText,FriendsText;//BABJI
public GameObject loginPanel,mainPanel;
public bool loggedIn;
void Awake ()
{
if (!FB.IsInitialized)
{
FB.Init(() =>
{
if (FB.IsInitialized)
FB.ActivateApp();
else
Debug.LogError("Couldn't initialize");
},
isGameShown =>
{
if (!isGameShown)
Time.timeScale = 0;
else
Time.timeScale = 1;
});
}
else
FB.ActivateApp();
}
void Start()
{
if (GameSaver.instance.isFBLogin) {
loginPanel.SetActive (false);
login_name.gameObject.SetActive (true);
mainPanel.SetActive (true);
// StartCoroutine (DelayLogIn ());
} else {
loginPanel.SetActive (true);
}
}
// IEnumerator DelayLogIn()
// {
// yield return new WaitForSeconds (0.1f);
//
// }
private void InitCallback ()
{
if (FB.IsInitialized) {
// Signal an app activation App Event
FB.ActivateApp();
// Continue with Facebook SDK
// ...
} else {
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
// Pause the game - we will need to hide
Time.timeScale = 0;
} else {
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
public void LoginCalled()
{
if (!FB.IsLoggedIn)
{
var perms = new List<string> (){ "public_profile", "email" };
FB.LogInWithReadPermissions (perms, AuthCallback);
}
else
{
//
}
// you are already logged in, do something
FB.API("me?fields=name", HttpMethod.GET, GetFacebookData);
FB.API("me/picture?type=square&height=128&width=128", HttpMethod.GET, GetProfilePicture);
login_name.gameObject.SetActive (true);
mainPanel.SetActive (true);
loginPanel.SetActive (false);
GameSaver.instance.isFBLogin=true;
GameSaver.instance.SaveGameData ();
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn)
{
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log(aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions)
{
Debug.Log(perm);
}
FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, GetFacebookData);
//FB.API("/me/picture?redirect=false", HttpMethod.GET, GetProfilePicture);
//BABJI
FB.API("me/picture?type=square&height=128&width=128", HttpMethod.GET, GetProfilePicture);
login_name.gameObject.SetActive (true);
mainPanel.SetActive (true);
loginPanel.SetActive (false);
GameSaver.instance.isFBLogin=true;
GameSaver.instance.SaveGameData ();
//BABJI
loggedIn = FB.IsLoggedIn;
}
else
{
Debug.Log("User cancelled login");
}
}
void GetFacebookData(IResult result)
{
fbname = result.ResultDictionary["name"].ToString ();
login_name.text = fbname ;
login_name.gameObject.SetActive (true);
fbNameText.text = fbname;
Debug.Log("fbName: " + fbname);
}
private void GetProfilePicture(IGraphResult result)
{
if (result.Error == null && result.Texture != null)
{
profilePic.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 ());
}
}
}
depending on what we have discussed above
try this code :
public void Awake()
{
// Init Facebook SDK
if (!FB.IsInitialized)
{
// Initialize the Facebook SDK Configuration
FB.Init(InitCallback, OnHideUnity);
}
else
{
// Already initialized, signal an app activation App Event
FB.ActivateApp();
}
}
private void InitCallback() {
if (FB.IsInitialized)
{
// Signal an app activation App Event
FB.ActivateApp();
}
else
{
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
// Here is the region where u r loggged in from facebook acccount
// Just put your Logic Here
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
}
else
{
Debug.Log("Facebook User cancelled login");
}
}
and here is what you need to call when u press a button,
public void LoginWithFaceBook()
{
var perms = new List<string>() { "public_profile", "email" };
FB.LogInWithReadPermissions(perms, AuthCallback);
}
also use this when u logout from your application
public void FacebookLogout()
{
if (FB.IsLoggedIn)
{
FB.LogOut();
}
}

How to play music from url in Xamarin.Forms?

I am gonna build Xamarin.Forms app which play music from url.
I used dependency service for each platform implementation.
[assembly: Dependency(typeof(AudioSerivce))]
namespace xxx.Droid
{
public class AudioSerivce : IAudio
{
int clicks = 0;
MediaPlayer player;
public AudioSerivce()
{
}
public bool Play_Pause (string url)
{
if (clicks == 0) {
this.player = new MediaPlayer();
this.player.SetDataSource(url);
this.player.SetAudioStreamType(Stream.Music);
this.player.PrepareAsync();
this.player.Prepared += (sender, args) =>
{
this.player.Start();
};
clicks++;
} else if (clicks % 2 != 0) {
this.player.Pause();
clicks++;
} else {
this.player.Start();
clicks++;
}
return true;
}
public bool Stop (bool val)
{
this.player.Stop();
clicks = 0;
return true;
}
}
}
and calling it
DependencyService.Get<IAudio>().Play_Pause("https://www.searchgurbani.com/audio/sggs/1.mp3");
If I check log, it seems everything is ok.
But I can't hear sound on android phone.
If anyone has some suggestion, please let me know.
Thanks
From:
https://forums.xamarin.com/discussion/64218/no-video-player-really
I suspect that there may be a problem related to an incompatibility between Octane Video player and Android Emulator, are you using a emulator/simulator?
Also another suggestion is to add this permissions:
INTERNET
WRITE_EXTERNAL_STORAGE
READ_EXTERNAL_STORAGE
To your Android app.
If that does not work try to use another url and compare if it working with other url's.

Categories