I try to implement Game Play Service Achievement in my game, but when achievement is unlocked, it does not pops up (show that achievement is unlocked) but when I open list of all achievements it shows that is unlocked. So my problem is, how to pops up achievement when it's unlocked ?
MainActivity.class
public static GoogleApiClient mGoogleApiClient;
private void callGooglePlay(){
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
PlayActivity.class
Games.Achievements.unlock(MainMenu.mGoogleApiClient, getResources().getString(R.string.e));
You need to call the getAchievementsIntent() to create the default achievements UI, and then call the startActivityForResult
startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),REQUEST_ACHIEVEMENTS);
More information about displaying achievements can be found on the documentation.
If you need a notification that's specific to the achievement being unlocked, you can try to use [setViewForPopups](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#setViewForPopups(com.google.android.gms.common.api.GoogleApiClient, android.view.View)) as suggested in this question.
Related
I currently have 4 accounts connected to the Google Drive app on my phone.
I am trying to play a .mp4 file from Google Drive using the following:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(file.getFile().getWebContentLink())));
When I select the Google Drive app to play the file, I am presented with a list of the 4 currently connected accounts.
I already know which account the file is from. Is there any way of passing this account to the the startActivity, maybe as part of the intent?
Try below code it may work and let me know it worked for you or not.:)
#Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.setAccountName("yourmaild#gmail.com")
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
I implemented a google account sign in button for my app, when I open the app (Android 6.0.1) and enter the sign in page, it shows a dialog saying This app won't run unless you update google play services
This is my code:
compile 'com.google.android.gms:play-services:9.2.1'
compile 'com.google.android.gms:play-services-auth:9.2.1'
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
.addApi(Auth.GOOGLE_SIGN_IN_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
I checked the google play services on my android device is 8.1.86
Is that because 8.1<9.2?
How to avoid this message for my users who has outdated google play services app?
In order to check Google Play Services you can use int isGooglePlayServicesAvailable (Context) method:
GoogleApiAvailability.getInstance()
.isGooglePlayServicesAvailable(context);
If the resultCode = SUCCESS then everything is fine. Otherwise, you decide what to do, if SERVICE_VERSION_UPDATE_REQUIRED you could ask if the user wants to update or you might have other login options.
If you what to show the original dialog call boolean showErrorDialogFragment (Activity activity, int errorCode, int requestCode).
I need to remove the “Have offline access” permission on my Android app.
In my application, when I click in sign me with Google it is showing me this:
I don't want that message
I'm using "GoogleApiClient" like this for the initialization:
// Build GoogleApiClient with access to basic profile
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
I search over internet, but I can't found how to do that in Android. I only found information about Web Server Applications and the approval_prompt parameter.
Someone have any idea of how to do that on Android?
Thanks and sorry for my poor English
That is the scope of permissions your application is requesting. Users need to know what permissions you want to access If you want to remove that you will have to remove
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
But then you will not be able to access the users account either.
I'm developing watch face for Android Wear. I want to show on the face the steps recorded only by the wear device. According to Google Documentation this is possible with HistoryApi.readDailyTotal()
According to the documentation:
The system does not require authorization to access the TYPE_STEP_COUNT_DELTA data type from the HistoryApi.readDailyTotal() method. This can be useful if you require step data for use in areas where you are unable to show the permissions panel (for example, Android Wear watch faces and activities or widget activities). For more information on how to use this data in a watch face, see Showing Information in Watch Faces.
Unfortunately this does not work for me - GoogleApiClient always returns Connection failed: 5 - This means:The client attempted to connect to the service with an invalid account name specified.
This is my client:
mFitnessApiClient = new GoogleApiClient.Builder(MyWatchFace.this)
.addApi(Fitness.HISTORY_API)
.addScope(Fitness.SCOPE_ACTIVITY_READ)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Any idea how to tackle this problem? I'm facing hard time with this.
I've had similar issues getting the total on the wearable (local only), and this worked for me: do not add any scopes, and be sure to call useDefaultAccount. Hope this helps!
Ex:
mFitnessApiClient = new GoogleApiClient.Builder(MyWatchFace.this)
.addApi(Fitness.HISTORY_API)
// Do not add any scopes if using the client on the watch
.addConnectionCallbacks(this)
.useDefaultAccount() // Use the default account
.addOnConnectionFailedListener(this)
.build();
I have tried to follow to Google documentation for Google Play Services but that's impossible, because Google documentation is the worst ever.
Anyway, I manged to setup project and add Google Play Services in my app, but I don't know how to keep connected state of player when user changes activity.
I have MainActivity, where extend BaseGameActivity, and then user click on button Play, I open GameActivity, where I play game, and when I finish game I want to submit score to Google Play Services Leaderboard, but I can't because it seems that I am not connected.
I extend MyActivity with BaseGameActivity
public class MainActivity extends BaseGameActivity
Then I on GameActivity extend this:
public GameActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
And then on onCreate use this:
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
And then when I finish game I try to submit score, but it seems that I am not connected.
if(mGoogleApiClient.isConnected()){
Games.Achievements.unlock(mGoogleApiClient,
getString(R.string.app_name));
Games.Leaderboards.submitScore(mGoogleApiClient,
getString(R.string.number_guesses_leaderboard),
clickCounter);
}
According to the docs, you need to call mGoogleApiClient.connect() aswell. They recommend using a button for sign in, but you can also do it at onStart():
#Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
If all goes well you'll receive the callback onConnected(Bundle connectionHint) which you are already implementing.
Play Game Services are really made with Fragments in mind. It is almost mandatory to use Fragments instead of Activities, and to have a single Activity in your app...