Google Drive V3 Rest API Play Video Thru Drive App - android

I currently have 4 accounts connected to the Google Drive app on my phone.
I am trying to play a .mp4 file from Google Drive using the following:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(file.getFile().getWebContentLink())));
When I select the Google Drive app to play the file, I am presented with a list of the 4 currently connected accounts.
I already know which account the file is from. Is there any way of passing this account to the the startActivity, maybe as part of the intent?

Try below code it may work and let me know it worked for you or not.:)
#Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.setAccountName("yourmaild#gmail.com")
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}

Related

Google Game Play Service Achievement does not pop up

I try to implement Game Play Service Achievement in my game, but when achievement is unlocked, it does not pops up (show that achievement is unlocked) but when I open list of all achievements it shows that is unlocked. So my problem is, how to pops up achievement when it's unlocked ?
MainActivity.class
public static GoogleApiClient mGoogleApiClient;
private void callGooglePlay(){
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
PlayActivity.class
Games.Achievements.unlock(MainMenu.mGoogleApiClient, getResources().getString(R.string.e));
You need to call the getAchievementsIntent() to create the default achievements UI, and then call the startActivityForResult
startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),REQUEST_ACHIEVEMENTS);
More information about displaying achievements can be found on the documentation.
If you need a notification that's specific to the achievement being unlocked, you can try to use [setViewForPopups](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#setViewForPopups(com.google.android.gms.common.api.GoogleApiClient, android.view.View)) as suggested in this question.

[Android]This app won't run unless you update google play services

I implemented a google account sign in button for my app, when I open the app (Android 6.0.1) and enter the sign in page, it shows a dialog saying This app won't run unless you update google play services
This is my code:
compile 'com.google.android.gms:play-services:9.2.1'
compile 'com.google.android.gms:play-services-auth:9.2.1'
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
.addApi(Auth.GOOGLE_SIGN_IN_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
I checked the google play services on my android device is 8.1.86
Is that because 8.1<9.2?
How to avoid this message for my users who has outdated google play services app?
In order to check Google Play Services you can use int isGooglePlayServicesAvailable (Context) method:
GoogleApiAvailability.getInstance()
.isGooglePlayServicesAvailable(context);
If the resultCode = SUCCESS then everything is fine. Otherwise, you decide what to do, if SERVICE_VERSION_UPDATE_REQUIRED you could ask if the user wants to update or you might have other login options.
If you what to show the original dialog call boolean showErrorDialogFragment (Activity activity, int errorCode, int requestCode).

Trouble with google drive

I want to create an application for browsing all files in google drive that are located in root folder. The problem is I can set up permissions only for creating and browsing files. But I have to browse the files which I upload in google drive via browser.
#Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
To retrieve files from the root folder use Drive.getRootFolder method.
The getRootFolder will returns a DriveFolder and it can be used to interact with the root folder. This method will return synchronously, and is safe to invoke from the UI thread.
DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), result.getDriveId());
folder.listChildren(getGoogleApiClient())
.setResultCallback(metadataResult);
public static final Scope SCOPE_FILE a Scope that gives 'drive.file' access to a user's drive. This scope give per-file access to files that have been created by, or specifically opened with the app.
The Scope implements SafeParcelable which describes an OAuth 2.0 scope to request. This has security implications for the user, and requesting additional scopes will result in authorization dialogs.
Here's a sample demo app, demo app illustrates all possible ways to talk to Drive service with the use of interfaces available in Google Play Services: https://github.com/googledrive/android-demos/

How to remove the “Have offline access” permission on Android using oAuth

I need to remove the “Have offline access” permission on my Android app.
In my application, when I click in sign me with Google it is showing me this:
I don't want that message
I'm using "GoogleApiClient" like this for the initialization:
// Build GoogleApiClient with access to basic profile
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
I search over internet, but I can't found how to do that in Android. I only found information about Web Server Applications and the approval_prompt parameter.
Someone have any idea of how to do that on Android?
Thanks and sorry for my poor English
That is the scope of permissions your application is requesting. Users need to know what permissions you want to access If you want to remove that you will have to remove
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
But then you will not be able to access the users account either.

Google+ Login with Play Services 6.5.87 (GoogleApiClient) - Android

In Play Services 6.1.71 I was using:
mPlusClient = new PlusClient.Builder(this,this,this).setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").setScopes(Scopes.PLUS_LOGIN, Scopes.PROFILE).build();
But in Google Play Services 6.5.87, Google suggest to change PlusClient to GoogleApiClient.Builder instead. But I'm not able to get user info as before:
mPlusClient.getAccountName()
or
mPlusClient.getCurrentPerson()
How can I retrieve the user info? I think Google documentation is out of date.
Hope you can help me. Thank you.
Use GoogleApiClient, not PlusClient. Sample:
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
To getAccountName() use Plus.AccountApi.getAccountName(mGoogleApiClient)
To getCurrentPerson() use Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)
Very nice example how to implement login with GoogleApiClient ...
Since it is whole tutorial I do not copy it here.

Categories

Resources