Example usage for com.google.api.client.googleapis.extensions.android.gms.auth UserRecoverableAuthIOException getIntent

List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth UserRecoverableAuthIOException getIntent

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.extensions.android.gms.auth UserRecoverableAuthIOException getIntent.

Prototype

public final Intent getIntent() 

Source Link

Document

Returns the Intent that when supplied to Activity#startActivityForResult(Intent,int) will allow user intervention.

Usage

From source file:ch.codezombie.insightsdashboard.CommonAsyncTask.java

License:Apache License

@Override
protected final Boolean doInBackground(Void... ignored) {
    try {/* ww w.  j a  v a2  s.c o m*/
        doInBackground();
        return true;
    } catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
        activity.showGooglePlayServicesAvailabilityErrorDialog(availabilityException.getConnectionStatusCode());
    } catch (UserRecoverableAuthIOException userRecoverableException) {
        activity.startActivityForResult(userRecoverableException.getIntent(),
                MainActivity.REQUEST_AUTHORIZATION);
    } catch (IOException e) {
        Utils.logAndShow(activity, MainActivity.TAG, e);
    }
    return false;
}

From source file:com.afrozaar.jazzfestreporting.MainActivity.java

License:Apache License

private void directTag(final VideoData video) {
    final Video updateVideo = new Video();
    VideoSnippet snippet = video.addTags(Arrays.asList(Constants.DEFAULT_KEYWORD,
            Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST)));
    updateVideo.setSnippet(snippet);//w w  w. j  a  v a 2 s .co  m
    updateVideo.setId(video.getYouTubeId());

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {

            YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential)
                    .setApplicationName(Constants.APP_NAME).build();
            try {
                youtube.videos().update("snippet", updateVideo).execute();
            } catch (UserRecoverableAuthIOException e) {
                startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                Log.e(TAG, e.getMessage());
            }
            return null;
        }

    }.execute((Void) null);
    Toast.makeText(this, R.string.video_submitted_to_ytdl, Toast.LENGTH_LONG).show();
}

From source file:com.afrozaar.jazzfestreporting.MainActivity.java

License:Apache License

private void loadUploadedVideos() {
    if (mChosenAccountName == null) {
        return;// ww  w  .j  av a 2  s.c  o m
    }

    setProgressBarIndeterminateVisibility(true);
    new AsyncTask<Void, Void, List<VideoData>>() {
        @Override
        protected List<VideoData> doInBackground(Void... voids) {

            YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential)
                    .setApplicationName(Constants.APP_NAME).build();

            try {
                /*
                 * Now that the user is authenticated, the app makes a
                * channels list request to get the authenticated user's
                * channel. Returned with that data is the playlist id for
                * the uploaded videos.
                * https://developers.google.com/youtube
                * /v3/docs/channels/list
                */
                ChannelListResponse clr = youtube.channels().list("contentDetails").setMine(true).execute();

                // Get the user's uploads playlist's id from channel list
                // response
                String uploadsPlaylistId = clr.getItems().get(0).getContentDetails().getRelatedPlaylists()
                        .getUploads();

                List<VideoData> videos = new ArrayList<VideoData>();

                // Get videos from user's upload playlist with a playlist
                // items list request
                PlaylistItemListResponse pilr = youtube.playlistItems().list("id,contentDetails")
                        .setPlaylistId(uploadsPlaylistId).setMaxResults(20l).execute();
                List<String> videoIds = new ArrayList<String>();

                // Iterate over playlist item list response to get uploaded
                // videos' ids.
                for (PlaylistItem item : pilr.getItems()) {
                    videoIds.add(item.getContentDetails().getVideoId());
                }

                // Get details of uploaded videos with a videos list
                // request.
                VideoListResponse vlr = youtube.videos().list("id,snippet,status")
                        .setId(TextUtils.join(",", videoIds)).execute();

                // Add only the public videos to the local videos list.
                for (Video video : vlr.getItems()) {
                    if ("public".equals(video.getStatus().getPrivacyStatus())) {
                        VideoData videoData = new VideoData();
                        videoData.setVideo(video);
                        videos.add(videoData);
                    }
                }

                // Sort videos by title
                Collections.sort(videos, new Comparator<VideoData>() {
                    @Override
                    public int compare(VideoData videoData, VideoData videoData2) {
                        return videoData.getTitle().compareTo(videoData2.getTitle());
                    }
                });

                return videos;

            } catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
                showGooglePlayServicesAvailabilityErrorDialog(availabilityException.getConnectionStatusCode());
            } catch (UserRecoverableAuthIOException userRecoverableException) {
                startActivityForResult(userRecoverableException.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                Utils.logAndShow(MainActivity.this, Constants.APP_NAME, e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(List<VideoData> videos) {
            setProgressBarIndeterminateVisibility(false);

            if (videos == null) {
                return;
            }

            mUploadsListFragment.setVideos(videos);
        }

    }.execute((Void) null);
}

From source file:com.afrozaar.jazzfestreporting.ResumableUpload.java

License:Apache License

private static void requestAuth(Context context, UserRecoverableAuthIOException userRecoverableException) {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    Intent authIntent = userRecoverableException.getIntent();
    Intent runReqAuthIntent = new Intent(MainActivity.REQUEST_AUTHORIZATION_INTENT);
    runReqAuthIntent.putExtra(MainActivity.REQUEST_AUTHORIZATION_INTENT_PARAM, authIntent);
    manager.sendBroadcast(runReqAuthIntent);
    Log.d(TAG, String.format("Sent broadcast %s", MainActivity.REQUEST_AUTHORIZATION_INTENT));
}

From source file:com.bangz.shotrecorder.MainActivity.java

License:Apache License

private void saveFileToDrive() {
    Thread t = new Thread(new Runnable() {

        @Override/*from ww w . j a  v a2s .co  m*/
        public void run() {
            try {
                java.io.File fileContent = new java.io.File(dbfileUri.getPath());
                FileContent mediaContent = new FileContent(null, fileContent);

                // File's metadata.
                File body = new File();
                body.setTitle(fileContent.getName());
                body.setDescription("Shot Recorder Database file");
                body.setMimeType("");
                body.setParents(Arrays.asList(new ParentReference().setId("appdata")));

                File file = googleDriveService.files().insert(body, mediaContent).execute();
                if (file != null) {
                    ShowToast("Backup successful.");
                }
            } catch (UserRecoverableAuthIOException e) {
                startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    });
    t.start();
}

From source file:com.bangz.shotrecorder.MainActivity.java

License:Apache License

private void restoreFileFromDrive() {

    Thread t = new Thread(new Runnable() {
        @Override/*  w w  w. j  a v a2  s. c  o m*/
        public void run() {
            try {
                File dbfile = getFileFromDrive();
                if (dbfile != null) {
                    java.io.File tofile = getDatabasePath(ShotRecordProvider.DATABASE_NAME);
                    downloadFileFromDrive(dbfile, new FileOutputStream(tofile));

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            refreshData();
                        }
                    });
                }
            } catch (UserRecoverableAuthIOException e) {
                startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    t.start();
}

From source file:com.bibibig.yeon.navitest.task.TaskListAsyncTask.java

License:Apache License

@Override
protected final Boolean doInBackground(Void... ignored) {
    try {//w  w  w. j  a  v  a2  s .c om
        doInBackground();
        return true;
    } catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
        activity.showGooglePlayServicesAvailabilityErrorDialog(availabilityException.getConnectionStatusCode());
    } catch (UserRecoverableAuthIOException userRecoverableException) {
        activity.startActivityForResult(userRecoverableException.getIntent(), BasicInfo.REQUEST_AUTHORIZATION);
    } catch (IOException e) {
        Utils.logAndShow(activity, activity.TAG, e);
    }
    return false;
}

From source file:com.bingzer.android.driven.gdrive.app.GoogleDriveActivity.java

License:Apache License

private void authenticate() {
    Credential credential = new Credential(this, googleAccount.getSelectedAccountName());
    storageProvider.authenticateAsync(credential, new Task.WithErrorReporting<Result<DrivenException>>() {
        @Override/*from  w  w w.  j  av  a2 s  .c  o m*/
        public void onCompleted(Result<DrivenException> result) {
            if (result.isSuccess())
                successfullyAuthenticated();
            else {
                if (result.getException().getCause() instanceof UserRecoverableAuthIOException) {
                    UserRecoverableAuthIOException exception = (UserRecoverableAuthIOException) result
                            .getException().getCause();
                    startActivityForResult(exception.getIntent(), REQUEST_AUTHORIZATION);
                } else {
                    onError(result.getException());
                }
            }
        }

        @Override
        public void onError(Throwable error) {
            Log.e(storageProvider.getName(), error.getMessage(), error);
            finish();
        }
    });
}

From source file:com.bufarini.reminders.ui.tasklists.ListManager.java

License:Apache License

private void authorise(final String accountName, final int requestCode,
        final IfAlreadyAuthorised ifAlreadyAuthorised, final ImageButton syncButton) {
    if (!isAccountAuthorised(accountName)) {
        final Activity activity = getActivity();
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(activity, TASKS_SCOPES);
        credential.setSelectedAccountName(accountName);
        final Tasks googleService = new Tasks.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(),
                credential).setApplicationName(DateUtils.getAppName(activity)).build();
        new Thread(new Runnable() {
            public void run() {
                try {
                    googleService.tasklists().list().execute();
                    saveAuthorisationForAccount(accountName);
                    isSyncWithGTasksEnabled = true;
                    ifAlreadyAuthorised.doAction();
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            syncButton.setVisibility(View.VISIBLE);
                        }/* w  w w . j  a va 2s  . com*/
                    });
                } catch (UserRecoverableAuthIOException userRecoverableException) {
                    startActivityForResult(userRecoverableException.getIntent(), requestCode);
                } catch (IOException e) {
                    Log.e(LOGTAG,
                            "authorise() :: cannot contact google servers for account +\"" + accountName + "\"",
                            e);
                }
            }
        }).start();
    } else
        ifAlreadyAuthorised.doAction();
}

From source file:com.dsna.android.main.MainActivity.java

License:Apache License

public void handleUserRecoverableAuthIOException(UserRecoverableAuthIOException ex) {
    this.startActivityForResult(ex.getIntent(), REQUEST_AUTHORIZATION);
}