簡體   English   中英

Google Play服務設計

[英]Design of Google Play Services

想進一步了解Google Play服務的設計。

要使用它,我們需要創建一個GoogleApiClient對象(請參見下面的代碼),然后我們需要添加我們感興趣的API。

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */,
                  this /* OnConnectionFailedListener */)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.build();

任何機構都可以幫助我如何構建整個機制。 本文是完整的幫助文章, 網址為http://wiresareobsolete.com/2016/06/play-services-complexity/,但我想了解更多詳細信息。

您可以嘗試正式文檔-Google Play服務概述

借助Google Play服務,您的應用可以利用由Google提供的最新功能,例如地圖,Google +等,並通過Google Play商店以APK的形式分發自動平台更新。 這樣一來,您的用戶可以更快地收到更新,並且可以更輕松地集成Google必須提供的最新信息。

在此處輸入圖片說明

該圖顯示了Google API客戶端如何提供接口來連接和調用任何可用的Google Play服務,例如Google Play游戲和Google雲端硬盤。

首先,您必須先為Android SDK安裝Google Play服務庫(版本15或更高版本)。 如果尚未執行此操作,請按照“設置Google Play服務SDK”中的說明進行操作。

這是一個實現回調接口並將其添加到Google API客戶端的活動的代碼示例:

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import gms.drive.*;
import android.support.v4.app.FragmentActivity;

public class MyActivity extends FragmentActivity
        implements OnConnectionFailedListener {
    private GoogleApiClient mGoogleApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create a GoogleApiClient instance
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */,
                                  this /* OnConnectionFailedListener */)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .build();

        // ...
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // An unresolvable error has occurred and a connection to Google APIs
        // could not be established. Display an error message, or handle
        // the failure silently

        // ...
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM