Google Play Services fixes for GMS 1.4 and 2.2 for Android GM version: GM: Studio 1.4.9999 Standard (2018-08-30) and GM Studio 2.2.1 Mobile (2018-12-05) Target platform: Android Download: https://appsurdgames.com/tutorials.html Links: N/A Latest change: 2019-03-18 Level: Advanced Summary In this small tutorial, we will present a few fixes for the Google Play Services asset. Specifically, the fixes are for version 3.0.1 from May 17, 2018, made by YoYo Games, which is downloadable for free on the Marketplace: https://marketplace.yoyogames.com/assets/2008/google-play-services. We present fixes for local/remote push notifications for GMS 1.4 and 2.2, improve the white rectangular notification icons when using Firebase for GMS 1.4 and changing the standard errors of logging in to Google Play Games for GMS 1.4 and 2.2. Moreover, we show a way for handling logins differently for GMS 1.4 and 2.2. The extension itself can be downloaded from https://appsurdgames.com/tutorials.html. Table of contents Problem 1: Local and remote push notifications do not work while using SDK 26 or up as maximum SDK Problem 2: I have GMS 1.4 and I experience white rectangular notification icons from my app Problem 3: I do not like the standard ‘failed-to-login’ Google Play Games messages Problem 4: I do not like the Toast message when a rewarded video ad has been watched Improvement 1: I do want to want to automatically login users for GPG Conclusion Frequently Asked Questions Changelog Introduction Google Play Services are an interesting feature for Android games to keep users interacted with each other using highscore lists, achievements and more. YoYo Games has provided an extension for this, however, it is outdated. It is not expected to be updated before Q3 2019: https://help.yoyogames.com/hc/en-us/articles/231719448-GMS2-Roadmap. Therefore we decided to write some step-by-step guides to improve / change some functionality of the asset. You do not need any Java knowledge, just follow the steps! In order to be prepared to understand this tutorial, I assume you have read https://help.yoyogames.com/hc/en-us/articles/360004274212-Android-Google-Play-Services-Logging-In about logging in to the Google Play Services. Problem 1: Local and remote push notifications do not work while using SDK 26 or up as maximum SDK Introduction Do you want to know how Push Notifications work? Then please read our tutorial: https://forum.yoyogames.com/index.php?threads/push-notifications-on-android.13769. In the GooglePlayServicesExtension, there is a Java class which sends the notifications. This is old / deprecated code, which doesn't work anymore when you select an API level which is 26 or up. Above API 26, it is obligatory to make use of “Channels” which is not incorporated in YoYo’s version. For API 25 and below, the functionality still works because of Google's backward compatibility policy. However, as you currently need to select API 26 or up to be able to create or update your app, it is very important to find a solution for this, which we did! What did you do? Warning, technical stuff coming up I created a channel which contains a channelId and a channelName. The channelId is the ID of the channel and the channelName is the name of the channel, which you can edit on lines 479 and 480 in GcmPush. Please note that the channelName is visible to users, so choose it wisely! (Perhaps the name of your app/game, or something like ‘Daily challenge’, or ‘General’). Most apps have notifications for multiple purposes, so they categorize these messages. This extension supports only one channel so ‘General’ or your app name would be a good choice. In the current (YoYo Games) extension, when the notification is created, only a so-called content is created. This is deprecated, you are now expected to deliver a channelId as well. This updated version of the GcmPush should solve this. Unfortunately, we need to do more work. The moment the app receives a notification, it creates a 'lock' such that the phone doesn't fall asleep. Then the notification icon is created and shown. Afterwards, the lock is removed. API 26+ has deprecated this 'lock', such that the code was completely ignored. Locking is simply not allowed anymore. To solve this, I decided to use JobScheduler to receive and handle the notification. You can read more information on how it works here: (https://medium.com/google-developers/scheduling-jobs-like-a-pro-with-jobscheduler-286ef8510129). I couldn’t reuse GcmIntentService so I had to make a new class because some different injections in the manifest were required. The only solution was to create a new Java file, which handles the notification correctly. Overview Added: GcmJobService.java Updated: GcmBroadcastReceiver.java GcmPush.java Removed/deprecated: GcmIntentService.java What do I need to do? When you already have the GooglePlayServices extension, make sure to remove it first and clean your cache. This is very important since GameMaker won’t notice when you replace an extension. Then download our Marketplace asset from https://appsurdgames.com/tutorials.html and add it to your project. Then go to the directory where the extension is located, which is "project.gmx/extensions/GooglePlayServicesExtension/AndroidSource/Java". Then go to lines 479 and 480 in GcmPush and change the channelName to something else. We recommend to change its value to ‘General’ or to the name of your app. When you download and inspect our code, you will notice one extra thing. Every notification has a group key. Therefore we added a summary notification, which combines each notification with the same group key. This is useful because you generally don’t want to receive every notification separately. This is done automatically (in our version), so you don’t need to edit things here. Conclusion Now you are done! All local and remote push notifications should be working again! Please report to us if it doesn’t work for you, so we can have a look at it. Problem 2: I have GMS 1.4 and I experience white rectangular notification icons from my app Introduction If you are still using GCM (Google Cloud Messaging) for push notifications, you will see colorful icons. However, this service is deprecated and will be shut down in April 2019. You can read more information on GCM here: https://developers.google.com/cloud-messaging/faq. Push notifications should be implemented using Firebase. You should create a new Firebase account (or login with your existing one) and add your app. The required API’s will automatically be added to your project on Google Cloud Platform (https://console.cloud.google.com/apis/). More information about push notifications can be found in our tutorial: https://forum.yoyogames.com/index.php?threads/push-notifications-on-android.13769. This all works great, but the only problem is the notification icon design. The following text was extracted from the official Android documentation: “Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.” GameMaker Studio simply takes the application icon as push notification. There is no way in GameMaker Studio to add a custom icon for the notification, so we have come up with a new method to fix this. What did you do? I tried to add custom icons to the APK file but that didn’t work. Also trying injecting the icons in the cache folder doesn’t work either. But then I found this article for GMS 2: https://help.yoyogames.com/hc/en-us/articles/360012115932-Android-How-To-Add-Adaptive-Icons-into-Projects-Made-with-GMS2-v2-1-5-or-v2-2-0 which shows a way to add adaptive icons to your APK file. I tried to do it the same way as described in the article with success! Now I was able to link to the custom files in the Java code in the extension. What do I need to do? Go to your GameMaker installation folder: “..\gamemaker_studio\Android\runner\ProjectFiles\src\main\res”. I’m using Steam and for me it was: “C:\Program Files (x86)\Steam\steamapps\common\gamemaker_studio\Android\runner\ProjectFiles\src\main\res”. Then you need to add the following folders: drawable-mdpi-v4 drawable-hdpi-v4 drawable-xhdpi-v4 drawable-xxhdpi-v4 drawable-xxxhdpi-v4 In each folder, you need to place an icon named “ic_notification.png”. This icon must be transparent! This means every pixel you place in the icon will be white. Make sure you remove the pixels you don’t want to see on the icon. Sizes of the icons are as follows: mdpi 24px hdpi 36px xhdpi 48px xxhdpi 72px xxxhdpi 96px After you have added all icons, it is time to build your app. The folders containing the icons will be placed inside the cache of your GMS project. This means you can remove them from the installation folder after you built your app. BUT if you clean the cache of your project, you need to add them again and build the app again. WARNING: the installation folder is the same for every project. When you open another project, you have to remove the created folder structure or that project will get the same icons! You also need to change some lines in the Google Play Services extension. First download our Google Play Services Extension, and open GcmPush.java. Then scroll down to line 490 and 499. Change “R.drawable.icon” to “R.drawable.ic_notification” (or use the commented code). With this code, you are telling the notification it needs to use your custom icon. We just changed the icon and now we need to change this in the manifest as well. Right-click Extensions->GooglePlayServicesExtension in your project, open the Android tab, and insert the following code into the manifest under Application level: Code: <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_notification" /> Conclusion This is not a clean fix, however it is a possible method to get the right notifications. Official implementation needs to be done by YoYo Games, but for now, it could solve your problem. Please report if it doesn’t work for you. Problem 3: I do not like the standard ‘failed-to-login’ Google Play Services messages Introduction In YoYo’s asset, failing to login to Google Play Services pops up a show_message_async() message with some text pre-entered by YoYo Games. Most of the time, this text is “failed to login”. Now, this looks rather ugly and you might not want this. We have fixed this. What did you do? We changed every call from Java to the internal show_message_async() function into a call to show_debug_message(). This means the information isn’t lost while debugging but is not shown to end-users. What do I need to do? Nothing, just downloading our asset is enough. You can still use GameMaker’s functions to determine if the login was successful or not. Problem 4: I do not like the Toast message when a rewarded video ad has been watched Introduction In YoYo’s asset, when the user has watched a video advertisement, a Toast message will be displayed. This message contains which reward the player receives. A Toast message is a small popup with a line of text. It is possible to trigger the asynchronous event when a video has been watched. I prefer my own custom message to be displayed at that moment. You can do that inside the asynchronous event. See the official help article here: https://help.yoyogames.com/hc/en-us/articles/360002971751-iOS-and-Android-Google-Mobile-Ads-Setup What did you do? I found the line of code inside “GooglePlayServicesExtension.java”. I simply commented out line 256. What do I need to do? Nothing, just downloading our asset is enough. You can still use GameMaker’s functions to handle the completion of the rewarded video. If you in some case want to use this Toast message, then go to line 256 in “GooglePlayServicesExtension.java” and uncomment that line. Improvement 1: Google Play Games logs in automatically every time I start my application, and I don’t want that Introduction As described in https://help.yoyogames.com/hc/en-us/articles/360004274212-Android-Google-Play-Services-Logging-In, you need to handle the logging in into the Google Play Services yourself. However, some players may not want to use the Google Play Services. So when they are asked every time the app launches to login, they may become annoyed about your app and might possibly delete it. To prevent this, one could handle logging in in a different way. You could ask the user to login, and save the result in a variable if they actually logged in. What do I need to do? When a user opens your application for the first time, you need to try to let the user log in to the Google Play Services. You can do this either by showing a button where the player can click on, or just popup the GPS login by calling achievement_login(). Then, after a second or 2, you need to check whether the player is actually logged in or not. Then create a variable (for example global.googleplayservices) whether the player has logged in or not. Save the variable in your (local) settings file. On the next launch of your app, check the content of global.googleplayservices (which you need to load from your save file first) and based on that, try to login to Google Play Services or not. Conclusion Now you are done! You have gained more control (and more comfortability for the user) how and when the login to the Google Play Services takes place. Conclusion Hopefully you learned how you can change the Java files of YoYo’s Google Play Services extension from the official Marketplace in such a way that it does exactly as you want! If you have more ideas or other problems, you can always post them below and we’ll see if we can do anything about it. We will keep an eye on the developments by YoYo Games and Google, and will update / change / remove parts of this tutorial whenever necessary. Please feel free to comment on or post any ideas or relevant stuff on the topic below, we might have some time to answer them or discuss about it. Frequently Asked Questions Did you mention this to YoYo Games? Yes, I send in a bug report. Problem 2 is unlikely to be fixed, as they are not updating GMS 1.4 anymore. For problem 3 and 4, the behavior is probably intentional, and they will therefore not change its feature. For problem 1, YoYo Games should fix this as soon as possible. Why did you not upload the extension on the Marketplace? Unfortunately, due to some problems regarding uploading GMS 1.4 assets, we decided to not use the Marketplace. In the future, when the tutorial is updated for GMS 2, this will definitely something which we'll consider. Changelog Changelog, huh? Yes, it’s actually just for me to check when and what I changed in the tutorial. Any people contributing something will be added too. 2019-03-18 First English version of the tutorial was written.