当前位置: 首页>>代码示例>>Java>>正文


Java AndroidHttp类代码示例

本文整理汇总了Java中com.google.api.client.extensions.android.http.AndroidHttp的典型用法代码示例。如果您正苦于以下问题:Java AndroidHttp类的具体用法?Java AndroidHttp怎么用?Java AndroidHttp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AndroidHttp类属于com.google.api.client.extensions.android.http包,在下文中一共展示了AndroidHttp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: search

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * Main search method, runs outside UI thread.
 */
private Book search(Book query) {
  Books books = new Books.Builder(AndroidHttp.newCompatibleTransport(), AndroidJsonFactory.getDefaultInstance(), null)
     .setApplicationName(BuildConfig.APPLICATION_ID)
     .build();

  try {
    // Executes the query
    Log.d(TAG, "Fetching details for "+query.getId());
    Books.Volumes.Get get = books.volumes().get(query.getId());
    final Volume execute = get.execute();
    BookDetails details = new BookDetails(execute);
    query.setDetails(details);
    Log.d(TAG, "Details loaded " + details.getSubtitle());
    return query;
  } catch (IOException e) {
    Log.e(TAG, "IO ex", e);
    return query;
  }
}
 
开发者ID:andviane,项目名称:google-books-android-viewer,代码行数:23,代码来源:DetailsLoader.java

示例2: fetch

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * Main search method, runs outside UI thread.
 */
@Override
public PrimaryResponse fetch(PrimaryRequest request) {
  Books books = new Books.Builder(AndroidHttp.newCompatibleTransport(), AndroidJsonFactory.getDefaultInstance(), null)
     .setApplicationName(BuildConfig.APPLICATION_ID)
     .setGoogleClientRequestInitializer(new BooksRequestInitializer(API_KEY))
     .build();

  try {
    // Executes the query
    Books.Volumes.List list = books.volumes().list(request.getQuery().getQueryString());
    list.setMaxResults(Long.valueOf(request.getTo() - request.getFrom()));
    list.setStartIndex(Long.valueOf(request.getFrom()));
    list.setFields("totalItems,items(volumeInfo(title,authors,pageCount,imageLinks/smallThumbnail),id)");

    Volumes execution = list.execute();
    ArrayList<Book> bookList = convert(execution);
    return new PrimaryResponse<>(bookList, execution.getTotalItems());
  } catch (IOException e) {
    Log.e(TAG, "IO ex", e);
    return null;
  }
}
 
开发者ID:andviane,项目名称:google-books-android-viewer,代码行数:26,代码来源:BookDataProvider.java

示例3: initGAEService

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
private void initGAEService() {
    if (service != null) {
        return;
    }
    if (mGoogleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext,
            "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(mGoogleSignInAccount.getEmail());
    Log.d(TAG, "credential account name" + credential.getSelectedAccountName());
    U2fRequestHandler.Builder builder = new U2fRequestHandler.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), credential)
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(
                        AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                        throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });
    service = builder.build();
}
 
开发者ID:googlesamples,项目名称:android-fido,代码行数:25,代码来源:GAEService.java

示例4: trainingsApi

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
public TrainingApi trainingsApi() {
    if (appEngineApi == null) {
        TrainingApi.Builder builder = new TrainingApi.Builder(AndroidHttp.newCompatibleTransport(),
                JacksonFactory.getDefaultInstance(), null)
                .setApplicationName(BuildConfig.APPLICATION_ID)
                .setRootUrl(APP_ENGINE_BASE_URL)
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        appEngineApi = builder.build();
    }
    return appEngineApi;
}
 
开发者ID:deniotokiari,项目名称:training-epam-2016,代码行数:17,代码来源:ApiManager.java

示例5: doInBackground

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("https://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:android-docs-samples,代码行数:23,代码来源:MainActivity.java

示例6: doInBackground

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("http://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:android-docs-samples,代码行数:23,代码来源:MainActivity.java

示例7: doInBackground

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
@Override
protected String doInBackground(Context... params) {
    if (jokeApiService == null) {
        final JokeApi.Builder builder = new JokeApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        jokeApiService = builder.build();
    }

    context = params[0];

    try {
        return jokeApiService.tellAJoke().execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
开发者ID:scarrupt,项目名称:Build-It-Bigger,代码行数:24,代码来源:GetJokeAsyncTask.java

示例8: getEndpoints

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * *
 *
 * @return ShoppingAssistant endpoints to the GAE backend.
 */
static ShoppingAssistant getEndpoints() {

    // Create API handler
    ShoppingAssistant.Builder builder = new ShoppingAssistant.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), getRequestInitializer())
            .setRootUrl(Constants.ROOT_URL)
            .setGoogleClientRequestInitializer(
                    new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(
                                final AbstractGoogleClientRequest<?>
                                        abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest
                                    .setDisableGZipContent(true);
                        }
                    }
            );

    return builder.build();
}
 
开发者ID:googlearchive,项目名称:MobileShoppingAssistant-sample,代码行数:28,代码来源:CloudEndpointBuilderHelper.java

示例9: setupRegistration

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * Setting up the registration object for communicating with the backend server
 */
private void setupRegistration() {
    if (mRegService == null) {
        Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null);

        //Run in the emulator, connect to local server
        if (Utils.runningOnEmulator()) {
            // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
            // otherwise they can be skipped
            builder
                    .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                    .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest.setDisableGZipContent(true);
                        }
                    });
        // Run on device, connect on real server
        } else {
            builder.setRootUrl("https://play-together-2015.appspot.com/_ah/api/");
        }
        mRegService = builder.build();
    }
}
 
开发者ID:rainbowbreeze,项目名称:playtogether,代码行数:29,代码来源:BackendHelper.java

示例10: setupGame

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * Setting up the registration object for communicating with the backend server
 */
private void setupGame() {
    if (mGameService == null) {
        Game.Builder builder = new Game.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null);

        //Run in the emulator, connect to local server
        if (Utils.runningOnEmulator()) {
            // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
            // otherwise they can be skipped
            builder
                    .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                    .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest.setDisableGZipContent(true);
                        }
                    });
            // Run on device, connect on real server
        } else {
            builder.setRootUrl("https://play-together-2015.appspot.com/_ah/api/");
        }
        mGameService = builder.build();
    }
}
 
开发者ID:rainbowbreeze,项目名称:playtogether,代码行数:29,代码来源:BackendHelper.java

示例11: get

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
public static Messaging get(Context context){
    if (messagingService == null) {
        SharedPreferences settings = context.getSharedPreferences(
                "Watchpresenter", Context.MODE_PRIVATE);
        final String accountName = settings.getString(Constants.PREF_ACCOUNT_NAME, null);
        if(accountName == null){
            Log.i(Constants.LOG_TAG, "Cannot send message. No account name found");
        }
        else {
            GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
                    "server:client_id:" + Constants.ANDROID_AUDIENCE);
            credential.setSelectedAccountName(accountName);
            Messaging.Builder builder = new Messaging.Builder(AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(), credential)
                    .setRootUrl(Constants.SERVER_URL);

            messagingService = builder.build();
        }
    }
    return messagingService;
}
 
开发者ID:google,项目名称:watchpresenter,代码行数:22,代码来源:MessagingService.java

示例12: setUpEndpoint

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
/**
 * Instantiates {@link FunnyApi} object
 */
private void setUpEndpoint() {
    if(funnyEndpoint == null) {  // Only do this once
        FunnyApi.Builder builder = new FunnyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setApplicationName(getResources().getString(R.string.app_name))
                        // options for running against local devappserver
                        // - 10.0.2.2 is localhost's IP address in Android emulator
                        // - turn off compression when running against local devappserver
                .setRootUrl("https://nanodegree-funny-endpoint-1024.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver

        funnyEndpoint = builder.build();
    }
}
 
开发者ID:josemontiel,项目名称:FunnyDroids,代码行数:24,代码来源:MainActivity.java

示例13: sync

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
private static void sync(Context context, boolean fullSync) {
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
  GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
      "server:client_id:988087637760-6rhh5v6lhgjobfarparsomd4gectmk1v.apps.googleusercontent.com");
  String accountName = preferences.getString(PREF_ACCOUNT_NAME, null);
  if (accountName == null || accountName.isEmpty()) {
    // If you haven't set up an account yet, then we can't sync anyway.
    Log.w(TAG, "No account set, cannot sync!");
    return;
  }

  boolean hasGetAccountsPermission = ContextCompat.checkSelfPermission(
      context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED;
  if (!hasGetAccountsPermission) {
    Log.w(TAG, "Don't have GET_ACCOUNTS permission, can't sync.");
    return;
  }

  Log.d(TAG, "Using account: " + accountName);
  credential.setSelectedAccountName(accountName);

  Syncsteps.Builder builder = new Syncsteps.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);
  builder.setApplicationName("Steptastic");
  new StepSyncer(context, builder.build(), fullSync).sync();
}
 
开发者ID:codeka,项目名称:steptastic,代码行数:27,代码来源:StepSyncer.java

示例14: EndpointsTaskBagImpl

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
public EndpointsTaskBagImpl(TodoPreferences preferences,
                            LocalTaskRepository localRepository) {
    super(preferences, localRepository, null);

    // Production testing
    //TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);

    // Local testing
    TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
            .setRootUrl("http://10.0.2.2:8080/_ah/api/")
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });

    taskApiService = builder.build();

}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:21,代码来源:EndpointsTaskBagImpl.java

示例15: getMBSEndpoint

import com.google.api.client.extensions.android.http.AndroidHttp; //导入依赖的package包/类
private Mobilebackend getMBSEndpoint() {

        // check if credential has account name
        final GoogleAccountCredential gac = mCredential == null
                || mCredential.getSelectedAccountName() == null ? null : mCredential;

        // create HttpRequestInitializer
        HttpRequestInitializer hri = new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest request) throws IOException {
                request.setBackOffPolicy(new ExponentialBackOffPolicy());
                if (gac != null) {
                    gac.initialize(request);
                }
            }
        };

        // build MBS builder
        // (specify gac or hri as the third parameter)
        return new Mobilebackend.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(),
                hri)
                .setRootUrl(Consts.ENDPOINT_ROOT_URL).build();
    }
 
开发者ID:pkill9,项目名称:POSproject,代码行数:24,代码来源:CloudBackend.java


注:本文中的com.google.api.client.extensions.android.http.AndroidHttp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。