I am trying to submit a score at a Google Game Play Leaderboard using the following code line:
if(mGoogleApiClient.isConnected()) {
Games.Leaderboards.submitScoreImmediate(mGoogleApiClient, "xxxxxxxxxxxxxxxxx", myScore).setResultCallback(new ResultCallback<Leaderboards.SubmitScoreResult>() {
#Override
public void onResult(Leaderboards.SubmitScoreResult arg0) {
Log.e(TAG, "getStatusCode= "+arg0.getStatus().getStatusCode());
Log.e(TAG, "score submitted: "+arg0.getScoreData().toString());
}
});
}
The score is not uploaded and I get the following error ScoreSubmissionData:
ScoreSubmissionData{PlayerId=xxxxxxxxxxxxxxxx, StatusCode=2, TimesSpan=DAILY, Result=null, TimesSpan=WEEKLY, Result=null, TimesSpan=ALL_TIME, Result=null}
StatusCode=2 means STATUS_CLIENT_RECONNECT_REQUIRED
I call the above line inside onConnected() method so it is sure that I am connected...
Try reconnecting or apply a Loop-switch sequence to handle error like this. You might want to check this example showing how to use STATUS_CLIENT_RECONNECT_REQUIRED of the com.google.android.gms.games.GamesClient class.
Base on the document:
STATUS_CLIENT_RECONNECT_REQUIRED
The AppStateClient is in an inconsistent state and must reconnect to the service to resolve the issue.
Also here is the list of AppStateClient that you may encounter.
Hope this helps.
I have found the solution.
The application i make was first build to an other Laptop.
Now i have bought a new Laptop, i installed Android Studio and tried to change some code lines. But when i submitted a Score my Google play account (API Manager) could not recognize my new Laptop because it had a different SHA1 key.
So i added my new SHA1 key at the credentials of the API Manager and everything was ok !!
Related
Instead of creating a light and a full version of my app, I decided to go the freemium way and offer a button to upgrade from the light to the full version.
The application is only available on the Google Play Store. So I created an in app purchase in the Play Store as described http://mobilecodetogo.blogspot.fr/2013/03/android-does-it-better-in-app-purchase.html.
Here is the code that I implemented :
if (buyFull) {
if (ParametresGeneraux.getPurchase().isManagedPaymentSupported()) {
String[] skus = {"ParametresGeneraux.getFullVersionSKU()"};
if (ParametresGeneraux.getPurchase().isItemListingSupported()) {
Product[] products = ParametresGeneraux.getPurchase().getProducts(skus);
String items = "";
if (products != null) {
for (Product p : products) {
items += p.getDescription();
}
}
Dialog.show("Produits intégrés", "Les produits intégrés sont " + items,
"OK", "Cancel");
}
// On achète
ParametresGeneraux.getPurchase().purchase("ParametresGeneraux.getFullVersionSKU()");
} else {
Dialog.show("Évolution impossible", "Impossible d'évoluer vers la version complète. Votre compte n'a pas été débité.", "OK", "Compris");
}
Where ParametresGeneraux.getPurchase() is doing Purchase.getInAppPurchase().
When I test it on the simulator with an Android skin (Nexus 5) the listing is not shown and it always results in a null pointer exception after executing the purchase :
java.lang.NullPointerException
at com.codename1.impl.javase.JavaSEPort$82$5$1.run(JavaSEPort.java:7936)
at com.codename1.ui.Display.processSerialCalls(Display.java:1152)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1096)
at com.codename1.ui.Display.mainEDTLoop(Display.java:997)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
On the contrary on the device few hours after submitting the app, the purchase is charged (so item is found and not null). However when I restart the app it is still in light version.
Here is how I test if it is a light version (in the init method from the main class) :
ParametresGeneraux.setPurchase(Purchase.getInAppPurchase());
ParametresGeneraux.setLightVersion(true);
if (ParametresGeneraux.getPurchase().isManagedPaymentSupported()) {
if (ParametresGeneraux.getPurchase().wasPurchased(ParametresGeneraux.getFullVersionSKU())) {
ParametresGeneraux.setLightVersion(false);
}
}
According to this 2014 SO question (and the mentioned RFE that has been closed since then) I assume wasPurchased should also work on Android. So I don't know why it does not work.
Actually my questions are :
Is it possible to test in app purchase with the simulator ?
Is wasPurchased the right method to pick up to check whether the user has bought the feature ?
Thanks a lot for giving me hints!
The simulator doesn't connect to google play and can return null for things you expect to be there. Notice that there are API's that indicate things such as if item listing is supported etc.
You can manipulate some elements of the purchase API via the simulator menu.
So to get rid of the NPE that appears right after the purchase() method returns in the simulator, the main class MUST implement PurchaseCallback interface!!!
The Main CN1 class is the one with the start() and init() methods not the state machine as [indicated by Shai][2]. This is a crucial part and should be stressed in the [Purchase tutorial][3] although this is well written in the API documentation :
public interface PurchaseCallback
Callback interface that the main class must implement in order for in-app-purchasing to work. Once the main class implements this interface the methods within it are invoked to indicate the various purchase states.
Now the itemPurchased() method from the PurchaseCallback implementation gets called when the after purchase() returns. And the simulator keeps track of the purchase in the CN1InAppPurchases file (.cn1 folder on Linux).
Furthermore now that the PurchaseCallback has been implemented, in the simulator (not on the Android device however) the wasPurchased() method returns the expected value depending on whether or not a previous purchase() call succeeded.
I was using an Android Native Plugin to connect to the leaderboard. At first, I made the application to connect to the google service using
GooglePlayConnection.instance.connect();
then when a button is clicked, the function below will be called.
public void ShowLeaderboard(string leaderboardName)
{
GooglePlayManager.instance.ShowLeaderBoard("leaderboard_score");
}
The application shows the connecting to box, but when i clicked on the button to show the leaderboard, nothing happens.
Then I tried to combine the two function into one like below, but the leaderboard is not showing either. The first click will show connecting to google play service box, but the second time did not show the leaderboard.
public void LeaderboardButton(){
if(GooglePlayConnection.state == GPConnectionState.STATE_CONNECTED) {
GooglePlayManager.instance.ShowLeaderBoard("leaderboard_score");
} else{
GooglePlayConnection.instance.connect ();
}
}
I would like to know is it because of the code or because of the settings in the android native window-> edit settings?
I'm assuming you have everything in your Google Play Developer Console setup right, with that being said after reading the documentation I believe line 3 should be GooglePlayManager.instance.ShowLeaderBoardsUI("leaderboard_score");
Lately, I have been trying to add static interstitial ads into my Unity game. For some reason, I could not get the system to show anything, or even react to me. After trying to work with the base Chartboost plugin, I tried to match a tutorial that I was following and purchased Prime31's Chartboost plugin and have been using that. However, neither the base plugin, nor Prime31's plugin, seem to be allowing me to show any ads. The code is pretty much done inside a single object, and it seems simple enough.
public class Advertisement : MonoBehaviour {
public string chartboostAppID = "5461129ec909a61e38b1505b";
public string chartboostAppSignature = "672b3b34e3e358e7a003789ddc36bd2bc49ea3b5";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
ChartboostAndroid.init (chartboostAppID, chartboostAppSignature, true);
ChartboostAndroid.cacheInterstitial(null);
}
void OnLevelWasLoaded(int level) {
ChartboostAndroid.cacheInterstitial(null);
if(Application.loadedLevelName == "Network Lobby") {
showAds();
}
}
public static void showAds() {
Debug.Log("Showing ad");
ChartboostAndroid.showInterstitial(null);
}
}
As you can see, it's pretty straightforward. This object is created at the game's splash screen, which appears only once, and it's never destroyed until the program ends. The goal is, whenever I enter the lobby scene, I want to see an ad before going to the lobby's menus. As it is, I do see the log printing "Showing ad", so I know the function is being called. However, nothing appears. Do I need to disable the GUI system first? Is there a step I'm missing?
I have already performed the following steps:
I have created and registered the app with chartboost, as well as double and triple checked the AppID and App Signature.
I have created a publishing campaign and registered it to the app.
I double-checked the orientation and confirmed that it's correct.
I registered this specific device as a test device.
The tutorial showed a call to ChartBoostAndroid.OnStart(), but there was no function like that for me to call. Perhaps that is from an older version?
I emailed Chartboost support and have not heard from them yet. I do not have that much time on this project, so if anyone can offer help, I'd appreciate it.
I am trying to integrate kiip in my android app . I have downloaded the latest sdk and sample example from https://kiip.me/ developers site . Also ,I have created a new app in kiip.me site.
Everything is fine but the problem is , I am getting KPResource null so showing No Promo .
Here is the listner that I am using in onStart() method:
public void onStart() {
super.onStart();
// The Activity context has been created by now, so start a new session.
KPManager.getInstance().startSession(mStartSessionListener);
}
private KPRequestListener<KPResource> mStartSessionListener = new KPRequestListener<KPResource>() {
public void onFinished(KPManager manager, KPResource response) {
if (response != null) {
toast("Start Session Finished w/ Promo");
} else {
toast("Start Session Finished No Promo");
}
manager.showResource(response);
// Start retrieving user's location
new LocationHelper(ExampleApplication.this).requestLocationUpdates(mLocationListener);
}
Here the response is always null , so getting the message : Start Session Finished No Promo . If anyone has got similar problem then please share your views.
Thanks in advance.
Have you enabled promos for test devices in the dashboard on https://kiip.me?
It sounds like it could be a settings issue on the server side. Try logging in and switching promo frequency and adding your test device.
Finally, the issue has been resolved. I think the problem was with my device , when I tested it next day with some other device, It worked for me.
I want to use Flickr API for downloading the images on Android Phone, can any one give or tell, me about the working sample of Flickr API on Andorid.
I have add the flickr.jar as the external library, and i have the "Key"and "Secret" but i do not know how to download the images.
All it takes is just 3 steps and you will have it implemented.
Step 1: Find your user id.
The easiest way is to use this service http://idgettr.com/
Step 2: Acquire you flickr api key
Just log-in to you account and click this link http://www.flickr.com/services/api/misc.api_keys.html
Step 3: Get the code from the example project from our blog
http://www.quintostdio.com/blog/archives/1117
Add you user id and api key on the FlickrActivity class (in the package com.quintostdio.test.flickr.ui) and run the example. You can copy paste the classes and add it to your project, with no more changes and it will work.
Hi I have built a Flickr Java library for Android: http://code.google.com/p/flickrj-android/
You'll need to look in their documentation on the Flickr site. Most likely will use the Java library and import it into your Android project.
Probably have to instantiate an object, using the Key and Secret. Once you have a valid authentication object, you'll use a provided method (from the docs) to get a picture.
Have a look here: http://www.flickr.com/services/api/
#Todd DeLand answer is pretty accurate even nowadays.
However, I'll speed you up the search and tell you that the flickrj-android is not anymore up to date, as you can check in the Downloads page https://code.google.com/archive/p/flickrj-android/downloads
The other project that is listed in the Flickr API page ( http://www.flickr.com/services/api/ ), Flickr4Java, it's definitely working nowadays since I just tested it today and so far is doing it's job pretty nicely.
Github repo: https://github.com/boncey/Flickr4Java
Gradle config to add in your project (be careful, since in the README it appears another Gradle configuration, which is for the project that Flickr4Java is based on, and is NOT working):
implementation "com.flickr4java:flickr4java:2.17"
As of today, Flickr4Java was last updated on Nov 11, 2017, which is not bad.
This is an example of how I sent a query to get the pictures around a certain location (latitude,longitude):
Thread thread = new Thread(new Runnable() {
#Override
public void run() {
try {
String apiKey = "MY_API_KEY";
String sharedSecret = "MI_API_SECRET";
REST rest = new REST();
Flickr flickrClient = new Flickr(apiKey, sharedSecret, rest);
SearchParameters searchParameters = new SearchParameters();
searchParameters.setLatitude(exampleLatitude);
searchParameters.setLongitude(exampleLongitude);
searchParameters.setRadius(3); // Km around the given location where to search pictures
PhotoList photos = flickrClient.getPhotosInterface().search(searchParameters,5,1);
} catch (Exception ex) {
Log.d(MapApplication.LOG_TAG, ex.getLocalizedMessage());
}
}
});
thread.start();
I would avoid flickr4java. I assumed it worked at first but after incorporating it in to my project I have found that it crashes the app intermittently. very annoying and has been a big waste of time :(. probably works fine under other java apps but does not seem to play well with android :(