I'm creating a turn based game on the Android platform using the API provided by Google.
At the end of the latest turn (in my case the third one), I'd like to set the winner but I have not found any API that permits this. Naturally I have all the data at the end of the game to set it.
I've not read something in the documentation - does this feature exist or should I handle it myself?
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
String myOponentId = mMatch.getParticipantId(playerId);
opponentResult = new ParticipantResult(myOponentId,
ParticipantResult.MATCH_RESULT_WIN, 1);
creatorResult = new ParticipantResult(playerId,
ParticipantResult.MATCH_RESULT_LOSS, 2);
Games.TurnBasedMultiplayer.finishMatch(getApiClient(), mMatch.getMatchId(),mMatch.getData(), creatorResult,opponentResult )
.setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
#Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
Related
We are going to implement Search Places functionality on Here Map Android Starter SDK, but we are facing problem on search places using SearchRequest method, getting error as #BAD_REQUEST,
SearchRequest searchRequest = new SearchRequest("shopping");
searchRequest.setSearchCenter(m_map.getCenter());
searchRequest.setSearchArea(new GeoCoordinate(18.467518, 73.777694), 5000);
searchRequest.execute(discoveryResultPageListener);
Getting Result as
private ResultListener<DiscoveryResultPage> discoveryResultPageListener = new ResultListener<DiscoveryResultPage>() {
#Override
public void onCompleted(DiscoveryResultPage discoveryResultPage, ErrorCode errorCode) {
if (errorCode == ErrorCode.NONE) {
/* No error returned,let's handle the results */
m_placeDetailButton.setVisibility(View.VISIBLE);
s_ResultList = discoveryResultPage.getItems();
for (DiscoveryResult item : s_ResultList) {
if (item.getResultType() == DiscoveryResult.ResultType.PLACE) {
PlaceLink placeLink = (PlaceLink) item;
addMarkerAtPlace(placeLink);
}
}
} else {
Toast.makeText(m_activity,
"ERROR:Discovery search request returned return error code+ " + errorCode,
Toast.LENGTH_SHORT).show();
}
}
};
Also we have implemented Here Maps Android SDK API on premium version,In that Search Places working fine. but in Premium version android APK size has been more than 65MB.
So how we can use Search Places in Starter SDK.
Thank you in advance!
Specify search location using either setSearchCenter or setSearchArea, if you use them at the same time you will get BAD_REQUEST error.
Premium SDK includes native libraries for armeabi-v7a and arm64-v8a architectures. You can split ABIs and generate multiple apks if you want to reduce final app's size.
When getting the mission manager, either by DJIMissionManager.getInstance() or djiAircraftInstance.getMissionManager(), the mission manager instance is never connected, ie missionManagerInstance.isConnected() always returns false, and proceeding without the isConnected check causes a crash. Am I missing a step in setting up or retreiving the mission manager?
A minute ago I asked the same question on their forums here.
Any help would be appreciated. I have been over their examples a thousand times but it seems all of the examples are using an older version of the sdk.
EDIT: More information that you could figure out but I'll add in for the heck of it.
Mission manager instance is not null because calling isConnected() returns false, and the drone is connected as well.
I just test the isMissionReadyToExecute and MissionManager.isConnected, i found that no matter when I call them, they always return true. So I consider that it should be the bugs inside the SDK.
And I found a walk around solution for this problem.
Initialize the mission.
// Step 1: create mission
DJIWaypointMission waypointMission = new DJIWaypointMission();
waypointMission.maxFlightSpeed = 14;
waypointMission.autoFlightSpeed = 4;
List<DJIWaypoint> waypointsList = new LinkedList<>();
// Step 2: create waypoints and prepare coordinates
DJIWaypoint northPoint = new DJIWaypoint(mHomeLatitude + 10 * Utils.ONE_METER_OFFSET, mHomeLongitude, 10f);
DJIWaypoint eastPoint = new DJIWaypoint(mHomeLatitude, mHomeLongitude + 10 * Utils.calcLongitudeOffset(mHomeLatitude), 20f);
DJIWaypoint southPoint = new DJIWaypoint(mHomeLatitude - 10 * Utils.ONE_METER_OFFSET, mHomeLongitude, 30f);
DJIWaypoint westPoint = new DJIWaypoint(mHomeLatitude, mHomeLongitude - 10 * Utils.calcLongitudeOffset(mHomeLatitude), 40f);
//Step 3: add actions
northPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.GimbalPitch, -60));
northPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartTakePhoto, 0));
eastPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartTakePhoto, 0));
southPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.RotateAircraft, 60));
southPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartRecord, 0));
westPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StopRecord, 0));
//Step 4: add waypoints into the mission
waypointsList.add(northPoint);
waypointsList.add(eastPoint);
waypointsList.add(southPoint);
waypointsList.add(westPoint);
waypointMission.addWaypoints(waypointsList);
mDJIMission = waypointMission;
prepare the mission.
mMissionManager.prepareMission(mDJIMission, new DJIMission.DJIMissionProgressHandler() {
#Override
public void onProgress(DJIMission.DJIProgressType type, float progress) {
setProgressBar((int)(progress * 100f));
}
}, new DJICompletionCallback() {
#Override
public void onResult(DJIError error) {
if (error == null) {
Utils.setResultToToast(mContext, "Success!");
} else {
Utils.setResultToToast(mContext, "Prepare: " + error.getDescription());
}
}
});
We are using Azure Mobile Services to Push notifications to a Xamarin Android and a Xamarin iOS and a Windows Universal App. The Windows Universal App has plenty of documentation around what we need, although we haven’t had a chance to implement it yet. However, both Xamarin Android and iOS are missing all documentation around Push Notifications. If you go to http://azure.microsoft.com/en-us/documentation/services/mobile-services/ and select Xamarin Android or Xamarin iOS and .NET Backend there are zero links for documentation around these APIs. After digging around a ton yesterday I found this: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-xamarin-android-get-started-push/ and http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-xamarin-ios-get-started-push/ both which were last updated in September of last year. The documentation was promised to be updated over 5 months ago.
When I use the Xamarin Component from Microsoft for Azure Mobile Services: http://components.xamarin.com/view/azure-mobile-services/ I am able to get the MobileServiceClient up and running, but not the Push notifications.
The API:
Push pushManager = MobileService.GetPush();
string deviceId = "what is this???";
//Option 1:
pushManager.RegisterNativeAsync(deviceId);
//Option 2:
GcmRegistration googleNotificationRegistration = new GcmRegistration(deviceId);
pushManager.RegisterAsync(googleNotificationRegistration);
Documentation I’m using:
Push.RegisterAsync:
https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mobileservices.push.registerasync.aspx
GcmRegistration: I can’t find any documentation for this class
Registration (Base class for GcmRegistration):
https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mobileservices.registration.aspx
Note: the parameter for Registration is not named deviceId it is named channelUri
Push.RegisterNativeAsync:
https://msdn.microsoft.com/en-us/library/dn643553.aspx
Note: the parameter of RegisterNativeAsync is not named deviceId it is named channelUri
My question is simple:
What is deviceId supposed to be? And how do I get it?
All the documentation above is for Winodws Universal Apps not for Xamarin Apps on Mono.
In the writing up of this question I have found articles about "Get Started with Notification Hubs":
Xamarin iOS - http://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-ios-get-started/
Xamarin Android - http://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-android-get-started/
Are these the example I should be using? They look old and the Android one mentions nothing about Azure Mobile Services. Should I not even be using the Azure Mobile Services Xamarin Component for Android?
tl;dr
deviceId should be just the GCMRegistrationId.
I looked into the source code of the implementations of the component DLLs and also Android SDKs.
Firstly, let's take a look to your option 1 and option 2 behind the scene. Basically both eventually do the same job of creating a GcmRegistration and passing it the internal RegistrationManager.
public Task RegisterAsync (Registration registration)
{
if (registration == null) {
throw new ArgumentNullException ("registration");
}
if (string.IsNullOrWhiteSpace (registration.PushHandle)) {
throw new ArgumentNullException ("registration.deviceId");
}
return this.RegistrationManager.RegisterAsync (registration);
}
public Task RegisterNativeAsync (string deviceId, IEnumerable<string> tags)
{
if (string.IsNullOrWhiteSpace (deviceId)) {
throw new ArgumentNullException ("deviceId");
}
GcmRegistration registration = new GcmRegistration (deviceId, tags);
return this.RegistrationManager.RegisterAsync (registration);
}
Then, one of the API calls that I can find involving the Registration.PushHandle (which is the deviceId you passed) is as below
public async Task<IEnumerable<Registration>> ListRegistrationsAsync (string deviceId)
{
MobileServiceHttpResponse mobileServiceHttpResponse = await this.client.HttpClient.RequestAsync (HttpMethod.Get, string.Format ("/push/registrations?deviceId={0}&platform={1}", new object[] {
Uri.EscapeUriString (deviceId),
Uri.EscapeUriString (Platform.Instance.PushUtility.GetPlatform ())
}), this.client.CurrentUser, null, true, null, MobileServiceFeatures.None);
return JsonConvert.DeserializeObject<IEnumerable<Registration>> (mobileServiceHttpResponse.Content, new JsonConverter[] {
new RegistrationConverter ()
});
}
I have then switched to Android Mobile Services SDK to look for similar code to find some hints. Sadly, it is found called pnsHandle in android but still no hints what it is.
/**
* Registers the client for native notifications with the specified tags
* #param pnsHandle PNS specific identifier
* #param tags Tags to use in the registration
* #return The created registration
* #throws Exception
*/
public Registration register(String pnsHandle, String... tags) throws Exception {
if (isNullOrWhiteSpace(pnsHandle)) {
throw new IllegalArgumentException("pnsHandle");
}
Registration registration = PnsSpecificRegistrationFactory.getInstance().createNativeRegistration(mNotificationHubPath);
registration.setPNSHandle(pnsHandle);
registration.setName(Registration.DEFAULT_REGISTRATION_NAME);
registration.addTags(tags);
return registerInternal(registration);
}
Finally, I guess the below example code from http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-push/#update-app should be calling the same API which now explain everything, i.e. deviceId is just the GCMRegistrationId.
#Override
public void onRegistered(Context context, final String gcmRegistrationId) {
super.onRegistered(context, gcmRegistrationId);
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
return null;
}
catch(Exception e) {
// handle error
}
return null;
}
}.execute();
}
I'm using a turn based multiplayer game.
Player 1 starts the game, Player 2 ends. But I always get errors.
This is the code for Player 2:
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
String myOponentId = mMatch.getParticipantId(playerId);
opponentResult = new ParticipantResult(myOponentId,
ParticipantResult.MATCH_RESULT_WIN, 1);
creatorResult = new ParticipantResult(playerId,
ParticipantResult.MATCH_RESULT_LOSS, 2);
Games.TurnBasedMultiplayer.finishMatch(getApiClient(), mMatch.getMatchId(),mMatch.getData(), creatorResult,opponentResult )
.setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
#Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
Log:
E/Volley﹕ [2816] a.a: Unexpected response code 400 for https://www.googleapis.com/games/v1/turnbasedmatches/ChEKCQixqozpwBoQAhACGAAgARDEt9LOpreWivoB/finish?language=en_GB
E/cc﹕ Failed to finish match: null
W/cc﹕ {"code":400,"errors":[{"message":"Invalid participantId with value 108607338309210360902.","domain":"global","reason":"invalid"}]}
Using finishMatch like in the example SkeletonActivity.java is working, but does not produce a winner:
Games.TurnBasedMultiplayer.finishMatch(getApiClient(), mMatch.getMatchId()
ok i messed up the nubers. have to set participant ids whichs is something like p_1 and not a number
myOponentParticipantId
I an developing a mobile app that loges in using Facebook username and pass. i am having runtime errors when trying to retrieve user details. I am using the as3 Facebook api.
ArgumentError: Error #1063: Argument count mismatch on Classes::WebViewLogin/userData(). Expected 0, got 2.
here is my code
public function callInit (){
FacebookMobile.init(APP_ID, onInit);
}
public function onInit(success:Object, fail:Object):void{
if (success){
trace("Already logged in");
}
else{
trace("Not logged in");
addChild(logInBtn);
logInBtn.x = logInBtn.y =200;
logInBtn.addEventListener(TouchEvent.TOUCH_BEGIN, logInbtnPressed);
}
}
private function logInbtnPressed(e:TouchEvent){
trace("-----------log in btn pressed-----------");
removeChild(logInBtn);
webView.stage = stage;
webView.viewPort = new Rectangle(10, 10, (stage.stageWidth -15), (stage.stageHeight - 15));
FacebookMobile.login( onLogin , this.stage, extendedPermissions, webView);
}
public function onLogin(success:Object, fail:Object):void{
trace ("onLogin function called");
if (success){
trace("Logged In\n");
//accessCamera.loggedIn();
getUserData();
addChild(logOutBtn);
logOutBtn.x = logInBtn.y =200;
logOutBtn.addEventListener(TouchEvent.TOUCH_BEGIN, onLogout);
}
else{
trace("Login Failed\n");
logInErr.text = "Error logging in to Facebook";
addChild(logInErr);
logInErr.border = true;
addChild(logInBtn);
logInBtn.x = logInBtn.y =200;
logInBtn.addEventListener(TouchEvent.TOUCH_BEGIN, logInbtnPressed);
}
}
public function getUserData(){
//-----------possible suspect line---------------//
FacebookMobile.api("/me" , userData);
}
public function userData(){
trace ("userdata method");
}
public function onLogout(success:Boolean):void {
removeChild(logOutBtn);
trace("Log out");
}
private function logOutbtnPressed(){
FacebookMobile.logout();
}
I am new to working with facebook and mobile apps and can find very little help with using this api. any help would be greatly appreciated.
edit any help on the problem i am having rather than alternative methods?
If you need something quickly you can buy GoViral from Milkman http://www.milkmangames.com/blog/tools/, they will provide Tutorials and email support for about $50
Maybe a better way will be to use the FreshPlanet ANE here :
https://github.com/freshplanet/ANE-Facebook
It's write especially for mobile so you can use direct connect from the device