I have implemented some Google Play Game Services features in my Android app as a separate Activity and I am now trying to rewrite my code as an (Action Bar Sherlock) fragme
I'm not sure how similar the API for Games is compared to Nearby (I think this should work), but when creating a GoogleApiClient for Nearby, I found that the objects passed in error callbacks (Status, ConnectionResult) are conveniently Parcelable. So I created an Activity that can be launched to handle these errors, and then pass whatever result it receives back to the caller.
https://gist.github.com/damien5314/c13ce47bca035c517dfbdfb2af488a73
Usage:
Nearby.Messages.publish(mNearbyApi, mMessage)
.setResultCallback(new ResultCallback() {
@Override
public void onResult(@NonNull Status status) {
Log.d(TAG, "Nearby publish result: " + getStatusCodeString(status.getStatusCode()));
if (status.getStatusCode() > 0) {
Intent intent = ResolveErrorActivity.buildIntent(getContext(), status);
startActivityForResult(intent, ResolveErrorActivity.REQUEST_RESOLVE_ERROR);
}
}
});
As long as you call startActivityForResult from a Fragment, it should get the result as usual.