I am facing problem in signing in using the google real time muleiplayer api's even after following all steps throughly as given in the documentation. Following is the link from where I have referred: https://developers.google.com/games/services/android/init.
I am not getting any error but my main activity extends BaseGameActivity when i start my game it calls onSignInFailed() automatically but i am calling the beginUserInitiatedSignIn() method from BaseGameActivity which is used for initialization of sign in on the button click none of the overridden methods gets called not even onSignInFailed() nor onConnectionFailed().
It's normal for it to call onSignInFailed on startup if have never signed in before. That's working as intended. Then, you should call beginUserInitiatedSignIn when your button is clicked, and then either onSignInFailed on onSignInSucceeded should be called.
I'd suggest putting some print statements around your code and BaseGameActivity to figure out what methods are being called to figure out what's happening.
By the way, the most common cause for sign-in errors is having a Client ID that's incorrectly set up. I'd recommend taking a look at the troubleshooting guide to see if there is a problem with your setup:
https://developers.google.com/games/services/android/troubleshooting
Related
I am working on an android app where I am supposed to log the flow in the Localytics(same like google analytics); that means how a user is walking through in my app. But flow in my app seems to be behaving weird because there are few Activities which can never be reached by certain Activities. But this flow is being logged in the Localytics. I followed the documentation accurately and events are being logged in fine.
I am writing these 3 lines of code in every activity's onResume() method as documentation says
onResume()
{
super.onResume();
Localytics.openSession();
Localytics.tagScreen("Splash");
Localytics.upload();
}
Now I have a couple of questions about these line of codes.
1. Is it the right approach to write Localytics.openSession(); in EVERY activity's onResume() method OR it should ONLY BE CALLED ONCE in the Splash activity?
2. Do I have to write Localytics.closeSession(); a method in every activity, for the Localytics to work properly?
3. Where can I find detailed information about what these methods do and how? Because There is not enough information in the API section of this Website(www.localytics.com).
My main concern and the priority is to make sure the flow of activities should be logged properly. So if someone has faced the same problem and found a working solution. Please share it here.
I've recently started using Crashlytics to monitor my app performance, however, I've noticed several occasions where my app would crash, but no crash report was sent to my dashboard.
This article says that it's okay to call Crashlytics.start() inside a Base activity class, but doesn't suggest it as a best practice.
I'm curious if not doing so would result in missing crash reports? I'd rather not make unnecessary calls if I don't have to. Currently I'm only calling Crashlytics.start() inside my app's launch activity specified by my androidmanifest.xml file.
I'm curious as to what happens when the user closes my app (by pressing the home button or launching a different activity) and the GC disposes of my activity while it's in the background. When the activity gets recreated and there is no call to Crashlytics.start(), will I be missing those crash reports?
If you don't want to lose any crashes, it is recommended to put the start() call as soon as possible.
And because the Application class is the first class to be instanced when you start your application, its onCreate() method is exactly where you should initialize the library.
If you refuse to do so, you may lose crashes related to your main Activity's inflation, for example.
I am new to android programming. I am planning to make an app that is location sensitive.
I am trying to use Google Play Services' Location Based APIs to detect the user's current location. For this I have been following the sample code and the details given here :-
developer.android.com- detect user's current location- Location APIs- Google Play Services
I am trying to understand the connection between the different method calls involved in detecting a user's current location. Now the above link although seems to have a lot of information, being a newbie, I find it difficult to connect the different method calls here.
So roughly what I understand form the code in the above URL is this :-
In the onCreate() of the MainActivity class we create a LocationClient. LocationClient is used to connect to the location services.
Now in the onStart() inside the MainActivity Class, we call locationClientObjet.connect().So it means that whenever the MainActivity of the app becomes visible, an attempt to connect to the location services is made.
Now before we even made the LocationClient we had already defined something known as the Location Services CallBacks.
So we implement the required interfaces and define the respective methods. So for example, the onConnected() gets called when the request to connect the client finishes successfully.
Now so far everything sounds good. The problem arises when I try to connect the above part with the below mentioned :-
Now before even we had defined the Location Services CallBacks, we had defined an inner class inside the MainActivity class called, ErrorDialogFragment. This class is I guess used to create an error fragment (like an alert box) that can display error messages to the user in case apparently the connection attempt to the Location Services fails due to some reason. So there are some things that I do not understand here :-
What is the use of CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000; The documentation in the page says :- Define a request code to send to Google Play services. This code is returned in Activity.onActivityResult. I do not understand this.
When is the onCreateDialog() inside the ErrorDialogFragment class get called. I do not find an explicit call to this method anywhere in the sample code mentioned on the page in the URL mentioned above.
What is the connection between the onConnectionFailed() and the error fragment.
There are 2 more methods defined :- onActivityResult() and servicesConnected(). I understand to some extent the use of servicesConnected() - it is used to see if the GooglePlay services is available. Is it a user defined method ? And is it not ding the same things that were being done inside the callback methods onConnected(), onDisConnected() and onConnectionFailed(). If not how are they different from servicesConnected() ?
And finally I just do not understand what is the use of onActivityResult(), what exactly are we trying to do here ?
Please pardon my ignorance. I am completely new to Android Programming and am trying to learn concepts clear and sound. Please correct me wherever I went wrong or misunderstood things. I tried looking through Vogella resources but could not find much help. Any good resources explaining details that would make my above concepts clear would be great help.
Q : What is the use of CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000; The documentation in > the page says :- Define a request code to send to Google Play services. This code is > returned in Activity.onActivityResult. I do not understand this.
A : CONNECTION_FAILURE_RESOLUTION_REQUEST is the request code you have defined, If MainActivity exits, onActivityResult gets the request code, one started with. i.e . CONNECTION_FAILURE_RESOLUTION_REQUEST (or USER_DEFINED_REQUEST_CODE)
This is specified by startActivityForResult(Intent,). This here is done through
connectionResult.startResolutionForResult(this,CONNECTION_FAILURE_RESOLUTION_REQUEST);
That itself calls startActivityForresult internally.
The usage is specified in the given sample code 'MainActivity.java' in the form of a comment before defining onActivityResult. This is quoted here as follows:
/*
* Handle results returned to this Activity by other Activities started with
* startActivityForResult(). In particular, the method onConnectionFailed() in
* LocationUpdateRemover and LocationUpdateRequester may call startResolutionForResult() to
* start an Activity that handles Google Play services problems. The result of this
* call returns here, to onActivityResult.
*/
Q : When is the onCreateDialog() inside the ErrorDialogFragment class get called. I do not > find an explicit call to this method anywhere in the sample code mentioned on the page in > the URL mentioned above.
A: It is called from here :
// Show the error dialog in the DialogFragment
errorFragment.show(getSupportFragmentManager(),
"Location Updates");
onCreateDialog adds the dialog to the dialog cache, and the show method calls it.
Q: What is the connection between the onConnectionFailed() and the error fragment.
A: onConnectionFailed is a callback method that is called when there is an error connecting the client to the google play service. The errors list can be found at
http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html in the 'Summary' section.
Now if the error occurred and it has some resolution, the error fragment will try to resolve it . Look at
http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html#hasResolution()
AND http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html#startResolutionForResult(android.app.Activity, int)
Here ‘this’ refers to the MainActivity and CONNECTION_FAILURE_RESOLUTION_REQUEST is the user defined request code called by startActivityForResult which is here implicitly called by
connectionResult.startResolutionForResult(
this,
CONNECTION_FAILURE_RESOLUTION_REQUEST);.
Q: There are 2 more methods defined :- onActivityResult() and
servicesConnected(). I understand to some extent the use of
servicesConnected() - it is used to see if the GooglePlay services is
available. Is it a user defined method ? And is it not ding the same
things that were being done inside the callback methods onConnected(),
onDisConnected() and onConnectionFailed(). If not how are they
different from servicesConnected() ?
A: Yes servicesConnected is a user defined method.
I am afraid it is not the same, it is checking if google play services is available or not through isGooglePlayServicesAvailable().
OnConnected() on the other hand will be called after isGooglePlayServicesAvailable returns true. So they act after the service is connected or disconnected , servicesConnected() just checks if it is connected or not.
Q: And finally I just do not understand what is the use of
onActivityResult(), what exactly are we trying to do here ?
This i hope is clear from the previous answers :)
I'm testing my multiplayer implementation using Google Play Game Services with 4 distinct devices. Everything is working fine but two things:
onInvitationReceived sometimes not firing (only sometimes ¿?)
Only in one device (Galaxy Ace), and only when is it who receives the invitation, then both players (inviter and invited) keeps waiting in the waiting room, so onActivity result is never fired. In waiting room I read "Invitation accepted" for both players, but it never closes...
Any advices?
Usually, when listeners are not firing, it's because they are getting garbage-collected. This happens if you use an anonymous listener (new Listener() { .... }). To avoid this, make your Activity implement the desired listener interface, and pass in this as the listener to GamesClient methods.
For more info, take a look at our troubleshooting guide, in the "Listeners not Called" section.
As for onActivityResult, if you are overring BaseGameActivity, make sure you are keeping the super.onActivityResult(...) line on your implementation of onActivityResult.
I am developing a simple app which will speak the contact name or an unknown number when call is received. I am implementing the app using broadcastReceiver and Services. If i run the app on emulator and start the call using DDMS, with 2 or 3 contacts saved, the app works fine since onInit() is called before tts.speak() runs.
Now when i try to run the same app on my android phone, onInit is called after the tts.speak(). From what i have understood while searching for an answer to this question, this happens due to tts.speak() not waiting for onInit to called.
One solution i found on this question was on How to wait for TextToSpeech initialization on Android but that didn't work either.
This question has been asked a lot of times but i couldn't find a working solution. This link suggested to use handler http://davidcheney.wordpress.com/2010/11/16/multitasking-in-android/ but being a newbie i have no idea as to how to implement that.
From what i understood i have to wait till onInit is called before i can use tts.speak() but i don't know how to do it.
Update
I was trying to call speak function outside the onInit since the data which was to be spoken was coming from elsewhere and i didn't want to do all the coding in onInit,this was not working. So i changed my code and finally somehow managed to run that speak() inside onInit().
Although the code is now running but there must be a way to call speak() outside onInit. So i will wait for a better answer else post my code for others facing same problem.
You either set a class member flag boolean mTtsInitialized and check this flag everytime you call speak or put the code to get the data to be spoken in onInit
This is not the most elegant way of handling this, I'm sure, but could you extend the class containing the onInit() method?
In this class, you could have a boolean variable that effectively "locks" your thread. Override the onInit() method, call super(), and then after super() set this value to true. Then, enter a loop that blocks the thread which calls tts.speak() until this value is true.
You'll want to keep in mind that you can't do this in the UI thread, because if you block that for too long it will crash your app.
I hope I understood your question correctly. :)