我正在Android应用程序中设置Google Cloud Messaging。首先,我初始化GoogleApiClient
以检查Play服务是否可用:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
尝试运行它会生成IllegalArgumentException: must call addApi() to add at least one API
,所以我还需要添加GCM Api,但老实说我在文档中找不到它。类似的东西:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(gcm.API) <----- WHAT HERE?
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
答案 0 :(得分:5)
似乎还没有办法将GoogleApiClient
与Google Cloud Messaging结合使用。在此之前,我们需要使用GooglePlayServicesUtil
方式。
答案 1 :(得分:0)
尝试此代码
GoogleApiClient apiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(
this /* FragmentActivity */
, this /* OnConnectionFailedListener */)
.addApi(Auth.CREDENTIALS_API)
.build();