com.google.api.client.extensions.android.http.AndroidHttp Java Examples

The following examples show how to use com.google.api.client.extensions.android.http.AndroidHttp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidGoogleDrive.java    From QtAndroidTools with MIT License 9 votes vote down vote up
public boolean authenticate(String AppName, String ScopeName)
{
    final GoogleSignInAccount SignInAccount = GoogleSignIn.getLastSignedInAccount(mActivityInstance);

    if(SignInAccount != null)
    {
        GoogleAccountCredential AccountCredential;
        Drive.Builder DriveBuilder;

        AccountCredential = GoogleAccountCredential.usingOAuth2(mActivityInstance, Collections.singleton(ScopeName));
        AccountCredential.setSelectedAccount(SignInAccount.getAccount());

        DriveBuilder = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), AccountCredential);
        DriveBuilder.setApplicationName(AppName);
        mDriveService = DriveBuilder.build();

        return true;
    }

    Log.d(TAG, "You have to signin by select account before use this call!");
    return false;
}
 
Example #2
Source File: MainActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the {@code result} of a completed sign-in activity initiated from {@link
 * #requestSignIn()}.
 */
private void handleSignInResult(Intent result) {
    GoogleSignIn.getSignedInAccountFromIntent(result)
            .addOnSuccessListener(googleAccount -> {
                    Log.d(TAG, "Signed in as " + googleAccount.getEmail());

                    // Use the authenticated account to sign in to the Drive service.
                    GoogleAccountCredential credential =
                        GoogleAccountCredential.usingOAuth2(
                                this, Collections.singleton(DriveScopes.DRIVE_FILE));
                    credential.setSelectedAccount(googleAccount.getAccount());
                    Drive googleDriveService =
                        new Drive.Builder(
                                AndroidHttp.newCompatibleTransport(),
                                new GsonFactory(),
                                credential)
                           .setApplicationName("Drive API Migration")
                           .build();

                    // The DriveServiceHelper encapsulates all REST API and SAF functionality.
                    // Its instantiation is required before handling any onClick actions.
                    mDriveServiceHelper = new DriveServiceHelper(googleDriveService);
                })
            .addOnFailureListener(exception -> Log.e(TAG, "Unable to sign in.", exception));
}
 
Example #3
Source File: GAEService.java    From security-samples with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example #4
Source File: MainActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
@Override
protected CollectionResponsePlace doInBackground(Void... params) {


  Placeendpoint.Builder endpointBuilder = new Placeendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
 
  endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);


  CollectionResponsePlace result;

  Placeendpoint endpoint = endpointBuilder.build();

  try {
    result = endpoint.listPlace().execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    result = null;
  }
  return result;
}
 
Example #5
Source File: MainActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
/**
 * Calls appropriate CloudEndpoint to indicate that user checked into a place.
 *
 * @param params the place where the user is checking in.
 */
@Override
protected Void doInBackground(Void... params) {
  CheckIn checkin = new com.google.samplesolutions.mobileassistant.checkinendpoint.model.CheckIn();

  // Set the ID of the store where the user is.
  checkin.setPlaceId("StoreNo123");

  Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);

  builder = CloudEndpointUtils.updateBuilder(builder);

  Checkinendpoint endpoint = builder.build();


  try {
    endpoint.insertCheckIn(checkin).execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return null;
}
 
Example #6
Source File: MainActivity.02.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
@Override
protected CollectionResponsePlace doInBackground(Void... params) {


  Placeendpoint.Builder endpointBuilder = new Placeendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
 
  endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);


  CollectionResponsePlace result;

  Placeendpoint endpoint = endpointBuilder.build();

  try {
    result = endpoint.listPlace().execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    result = null;
  }
  return result;
}
 
Example #7
Source File: MainActivity.02.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
/**
 * Calls appropriate CloudEndpoint to indicate that user checked into a place.
 *
 * @param params the place where the user is checking in.
 */
@Override
protected Void doInBackground(Void... params) {
  CheckIn checkin = new CheckIn();

  // Set the ID of the store where the user is.
  checkin.setPlaceId("StoreNo123");

  Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);

  builder = CloudEndpointUtils.updateBuilder(builder);

  Checkinendpoint endpoint = builder.build();


  try {
    endpoint.insertCheckIn(checkin).execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return null;
}
 
Example #8
Source File: MainActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
@Override
protected CollectionResponsePlace doInBackground(Void... params) {


  Placeendpoint.Builder endpointBuilder = new Placeendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
 
  endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);


  CollectionResponsePlace result;

  Placeendpoint endpoint = endpointBuilder.build();

  try {
    result = endpoint.listPlace().execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    result = null;
  }
  return result;
}
 
Example #9
Source File: MainActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
/**
 * Calls appropriate CloudEndpoint to indicate that user checked into a place.
 *
 * @param params the place where the user is checking in.
 */
@Override
protected Void doInBackground(Void... params) {
  CheckIn checkin = new com.google.samplesolutions.mobileassistant.checkinendpoint.model.CheckIn();

  // Set the ID of the store where the user is.
  checkin.setPlaceId("StoreNo123");

  Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);

  builder = CloudEndpointUtils.updateBuilder(builder);

  Checkinendpoint endpoint = builder.build();


  try {
    endpoint.insertCheckIn(checkin).execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return null;
}
 
Example #10
Source File: TictactoeActivity.java    From appengine-endpoints-tictactoe-android with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the activity is first created. It displays the UI, checks
 * for the account previously chosen to sign in (if available), and
 * configures the service object.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  settings = getSharedPreferences(TAG, 0);
  credential = GoogleAccountCredential.usingAudience(this, ClientCredentials.AUDIENCE);
  setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

  Tictactoe.Builder builder = new Tictactoe.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(),
      credential);
  service = builder.build();

  if (credential.getSelectedAccountName() != null) {
    onSignIn();
  }

  Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);
}
 
Example #11
Source File: MainActivity.java    From solutions-mobile-shopping-assistant-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * Calls appropriate CloudEndpoint to indicate that user checked into a place.
 *
 * @param params the place where the user is checking in.
 */
@Override
protected Void doInBackground(PlaceInfo... params) {

  CheckIn checkin = new CheckIn();
  checkin.setPlaceId(params[0].getPlaceId());

  Builder endpointBuilder = new Shoppingassistant.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
      CloudEndpointBuilderHelper.getRequestInitializer());

  CheckInEndpoint checkinEndpoint =
      CloudEndpointBuilderHelper.updateBuilder(endpointBuilder).build().checkInEndpoint();

  try {
    checkinEndpoint.insert(checkin).execute();
  } catch (IOException e) {
    String message = e.getMessage();
    if (message == null) {
      message = e.toString();
    }
    log.warning("Exception when checking in =" + message);
  }
  return null;
}
 
Example #12
Source File: CloudBackend.java    From io2014-codelabs with Apache License 2.0 6 votes vote down vote up
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();
    }
 
Example #13
Source File: EndpointsTaskBagImpl.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
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();

}
 
Example #14
Source File: MessagingService.java    From watchpresenter with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #15
Source File: CloudEndpointBuilderHelper.java    From MobileShoppingAssistant-sample with Apache License 2.0 6 votes vote down vote up
/**
 * *
 *
 * @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();
}
 
Example #16
Source File: TGDriveBrowser.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void open(final TGBrowserCallBack<Object> cb){
	try {
		this.drive = null;
		this.folder = null;
		this.httpTransport = AndroidHttp.newCompatibleTransport();
		
		TGDriveBrowserLogin login = new TGDriveBrowserLogin(this.findActivity(), this.settings, new TGBrowserCallBack<GoogleAccountCredential>() {
			public void onSuccess(GoogleAccountCredential credential) {
				Drive.Builder builder = new Drive.Builder(TGDriveBrowser.this.httpTransport, GsonFactory.getDefaultInstance(), credential);
				builder.setApplicationName(findActivity().getString(R.string.gdrive_application_name));
				TGDriveBrowser.this.drive = builder.build();
				
				cb.onSuccess(null);
			}
			
			public void handleError(Throwable throwable) {
				cb.handleError(throwable);
			}
		});
		login.process();
	} catch (Throwable e) {
		cb.handleError(e);
	}
}
 
Example #17
Source File: MainActivity.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #18
Source File: MainActivity.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #19
Source File: DriveSyncProvider.java    From science-journal with Apache License 2.0 6 votes vote down vote up
private void addServiceForAccount(AppAccount appAccount) {


    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    accountMap.put(
        appAccount,
        new DriveSyncManager(
            appAccount,
            AppSingleton.getInstance(applicationContext).getDataController(appAccount),
            transport,
            jsonFactory,
            applicationContext,
            driveSupplier,
            AppSingleton.getInstance(applicationContext)
                .getSensorEnvironment()
                .getDataController(appAccount)));
  }
 
Example #20
Source File: GAEService.java    From android-fido with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example #21
Source File: BaseMainDbActivity.java    From dbsync with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(Intent result) {
    GoogleSignIn.getSignedInAccountFromIntent(result)
            .addOnSuccessListener(googleAccount -> {
                Log.d(TAG, "Signed in as " + googleAccount.getEmail());

                // Use the authenticated account to sign in to the Drive service.
                GoogleAccountCredential credential =
                        GoogleAccountCredential.usingOAuth2(
                                this, Arrays.asList(DriveScopes.DRIVE_FILE, DriveScopes.DRIVE_METADATA, DriveScopes.DRIVE_READONLY,
                                        DriveScopes.DRIVE_METADATA_READONLY, DriveScopes.DRIVE_PHOTOS_READONLY));
                credential.setSelectedAccount(googleAccount.getAccount());

                googleDriveService =
                        new com.google.api.services.drive.Drive.Builder(
                                AndroidHttp.newCompatibleTransport(),
                                new GsonFactory(),
                                credential)
                                .setApplicationName("Drive API DBSync")
                                .build();

                // The DriveServiceHelper encapsulates all REST API and SAF functionality.
                // Its instantiation is required before handling any onClick actions.
                //mDriveServiceHelper = new DriveServiceHelper(googleDriveService);
            })
            .addOnFailureListener(exception -> Log.e(TAG, "Unable to sign in.", exception));
}
 
Example #22
Source File: BaseMainDbActivity.java    From dbsync with Apache License 2.0 6 votes vote down vote up
private void handleSignInONRecnnect() {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

    if  (account != null ){
        Log.d(TAG, "Signed in as " + account.getEmail());

        // Use the authenticated account to sign in to the Drive service.
        GoogleAccountCredential credential =
                GoogleAccountCredential.usingOAuth2(
                        this, Collections.singleton(DriveScopes.DRIVE_FILE));
        credential.setSelectedAccount(account.getAccount());

        googleDriveService =
                new com.google.api.services.drive.Drive.Builder(
                        AndroidHttp.newCompatibleTransport(),
                        new GsonFactory(),
                        credential)
                        .setApplicationName("Drive API DBSync")
                        .build();
    }
}
 
Example #23
Source File: PubsubPublisher.java    From weatherstation with Apache License 2.0 5 votes vote down vote up
PubsubPublisher(Context context, String appname, String project, String topic,
                int credentialResourceId) throws IOException {
    mContext = context;
    mAppname = appname;
    mTopic = "projects/" + project + "/topics/" + topic;

    mHandlerThread = new HandlerThread("pubsubPublisherThread");
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper());

    InputStream jsonCredentials = mContext.getResources().openRawResource(credentialResourceId);
    final GoogleCredential credentials;
    try {
        credentials = GoogleCredential.fromStream(jsonCredentials).createScoped(
                Collections.singleton(PubsubScopes.PUBSUB));
    } finally {
        try {
            jsonCredentials.close();
        } catch (IOException e) {
            Log.e(TAG, "Error closing input stream", e);
        }
    }
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            mHttpTransport = AndroidHttp.newCompatibleTransport();
            JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
            mPubsub = new Pubsub.Builder(mHttpTransport, jsonFactory, credentials)
                    .setApplicationName(mAppname).build();
        }
    });
}
 
Example #24
Source File: GmailAuthorizationActivity.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode) {
        case REQUEST_AUTHORIZATION:
            if (resultCode == RESULT_OK) {
                gmailResultListener.onSuccess(mService);
            }
            break;

        case REQUEST_ACCOUNT_PICKER:
            if (resultCode == RESULT_OK && data != null &&
                    data.getExtras() != null) {
                String accountName =
                        data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                if (accountName != null) {
                    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
                    editor.putString(PREF_ACCOUNT_NAME,accountName);
                    editor.apply();

                    mCredential.setSelectedAccountName(accountName);

                    mService = new Gmail.Builder(
                                AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential)
                                .setApplicationName(AppUtils.getApplicationName(this))
                                .build();
                    gmailResultListener.onSuccess(mService);
                }

            }
            break;
    }
    finish();
}
 
Example #25
Source File: PlaceDetailsActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the list of recommendations through appropriate CloudEndpoint.
 *
 * @param params the place for which to retrieve recommendations.
 * @return collection of retrieved recommendations.
 */
@Override
protected CollectionResponseRecommendation doInBackground(Place... params) {
  Recommendationendpoint.Builder endpointBuilder = new Recommendationendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
  endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);
  CollectionResponseRecommendation result;
  Recommendationendpoint endpoint = endpointBuilder.build();
  try {
    result = endpoint.listRecommendation().execute();
  } catch (IOException e) {
    e.printStackTrace();
    result = null;
  }
  return result;
}
 
Example #26
Source File: PlaceDetailsActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the list of offers through appropriate CloudEndpoint.
 * @param params the place for which to retrieve offers.
 * @return collection of retrieved offers.
 */
@Override
protected CollectionResponseOffer doInBackground(Place... params) {
    Offerendpoint.Builder endpointBuilder = new Offerendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
    endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);
    CollectionResponseOffer result;
    Offerendpoint endpoint = endpointBuilder.build();
    try {
      result = endpoint.listOffer().execute();
    } catch (IOException e){
      e.printStackTrace();
      result=null;
    }
    return result;
}
 
Example #27
Source File: BaseGmailProvider.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
private void checkGmailApiRequirements() {


        String accountName = PreferenceManager.getDefaultSharedPreferences(getContext())
                .getString(PREF_ACCOUNT_NAME, null);

        if (accountName != null) {
            GoogleAccountCredential mCredential = GoogleAccountCredential.usingOAuth2(
                    getContext().getApplicationContext(), Arrays.asList(SCOPES))
                    .setBackOff(new ExponentialBackOff());
            mCredential.setSelectedAccountName(accountName);

            if (!DeviceUtils.isGooglePlayServicesAvailable(getContext())) {
                DeviceUtils.acquireGooglePlayServices(getContext());
            }
            else{
                mService = new Gmail.Builder(
                        AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential)
                        .setApplicationName(AppUtils.getApplicationName(getContext()))
                        .build();
                authorized = true;
            }


        } else {
            GmailAuthorizationActivity.setListener(this);
            getContext().startActivity(new Intent(getContext(), GmailAuthorizationActivity.class));
        }

    }
 
Example #28
Source File: GCMIntentService.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
public GCMIntentService() {
  super(PROJECT_NUMBER);
  Deviceinfoendpoint.Builder endpointBuilder = new Deviceinfoendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
      new HttpRequestInitializer() {
        public void initialize(HttpRequest httpRequest) {
        }
      });
  endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
}
 
Example #29
Source File: CheckupReminders.java    From Crimson with Apache License 2.0 5 votes vote down vote up
public MakeRequestTask(GoogleAccountCredential credential) {
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    mService = new com.google.api.services.calendar.Calendar.Builder(
            transport, jsonFactory, credential)
            .setApplicationName("Google Calendar API Android Quickstart")
            .build();
}
 
Example #30
Source File: MainActivity.01.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * Calls appropriate CloudEndpoint to indicate that user checked into a place.
 *
 * @param params the place where the user is checking in.
 */
@Override
protected Void doInBackground(Void... params) {
  CheckIn checkin = new CheckIn();
  
  // Set the ID of the store where the user is. 
  // This would be replaced by the actual ID in the final version of the code. 
  checkin.setPlaceId("StoreNo123");

  Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
      null);
      
  builder = CloudEndpointUtils.updateBuilder(builder);

  Checkinendpoint endpoint = builder.build();
  

  try {
    endpoint.insertCheckIn(checkin).execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return null;
}