Access to Google Fit Activity Data - android

This is a Google Fit app screenshot.
My app don't work for some user if they don't activate this in Google fit app.
Is someone knows how to activate it directly in your app ?

Try checking the Google Fit samples on GitHub on how they are authorizing their app.
Based on the documentation - Authorization on Android:
The authorization flow is the following:
Your app requests a connection, with one or more scopes of access, to the fitness service.
Google Fit prompts the user to grant your app the required permissions.
If the user consents, your app can access fitness data of the types defined by the scope.
I think you should implement your error catch when your user didn't activate this in Google fit app like (Activate Required).
Hope this helps.

Related

Which specific Google fit scopes are required for a step counter app

We are trying to add step counter feature in an android app using fit api. The app was submitted for google OAuth (along with video) but got the following email from them:
How does user sign-up on your app and grants access to the sensitive scopes requested in verification(ensuring that the URL bar with the client ID is clearly visible) - Our App is native android App so can't show client ID on consent page. what's the alternate option?
OAuth consent screen/Permissions Page as seen by end users
How does your application use the requested scopes to provide services to developers
https://www.googleapis.com/auth/fitness.location.write
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.location.read```
We are using the below two datatypes in our application for Step counter functionality. Can you suggest *if we need anything beyond fitness.activity.read scope to add step counter in our app*?
```DataType.TYPE_STEP_COUNT_CUMULATIVE
DataType.TYPE_STEP_COUNT_DELTA```
Thanks
Zam

Android Auto Backup - ask user to login and select frequency?

I am learning about how to implement backup/restore for android as described here
It is said that "Doesn't require a user to be logged into your app. The user must be logged into the device with a Google account. Doesn't require a user to be logged into your app. The user must be logged into the device with a Google account."
But for example, if user isnt logged in any google account, can we ask within the app to login to google account and select frequency? For example, whatsapp is doing it on its settings? you can even change the account if you have multiple accounts? Otherwise user has to go to phone settings and has to enable this and most of the users dont even know that is available there.
So if I implement a google authentication within my app and get authentication token. how can I implement this? Any sample code or project?
I am using xamarin.android but I dont mind java code as well.
The Auto Backup is provided by android. You can enable it in the system setting.
When you enable it, you can set the location to backup, for example set a google account or let it backup to SD card. And you could also set frequency and which app you need to backup. It all sets in the system setting not in the app.
You could refer to this article for more information.

How to get Google Play Services currently connected account?

Many Google Applications allow you to switch between Google Accounts and show you the currently connected account.
For example Google Fit, Gmail, Google+, etc...
From the perspective of the code I call .connect() on the Google Client and enter a loop of
connection failed
launch automatic resolution
get activity result
retry connect
until I finally connect.
This is documented in many places, here for example: https://developers.google.com/android/guides/api-client
On the UX side what happens is that the user is presented with multiple dialogs asking every time something different.
One of the dialog ask to chose an Account between the ones available on the phone (it probably automatically resolve without user interaction if there's only one account configured).
How do you query the Google Client to know which account is currently connected?
I found no documentation about it anywhere.
The closest thing I found is this:
https://developers.google.com/android/reference/com/google/android/gms/common/AccountPicker
but I do not create the picker, it's something completely handled by the Play Services in the procedure I described above.
You have to request the Account resource with Google Plus API.
Add the following permission in the manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Then use this API to get the account that is logged in currently.
EDIT (addressing the comment):
In .builder add login scope as shown in the example and initiate the G+ Api as well. Since you do not need social scopes, this scope will give you access to currently authenticated user's information.
Once you setAccountName through the builder, you can access the Account resource for this user which you can get at anytime through getAccountName.
EDIT 2:
So apologies for not addressing the G+ context with last edit.
Here's a class in simple Google Sign In (Identity platform) which give you access to account resource.
More information in the official documentation.

Automatically sign into Google account on Android webview

This past week I've inundated myself with links and led myself in too many circles to count, so I thought I'd pose the question here. I have an Android app that displays webviews pointing to urls which the user must be signed in with their Google account to see (the backend is built in Google App Engine). Since the end user is likely to be signed into their Google account on their Android anyway, I'd like the sign-in process to be automatic. Currently, on the first webview the user opens up they are presented with the Google sign-in form and a really ugly subsequent page asking "would you like to allow example.appspot.com to use your Google account?"
That process is dreadful for user experience. I've seen precious few resources here and there concerning auto-login, but I'm frankly lost in the sea of almost-what-I-want-but-not-quite to be able to discern the direction I ought to be going.
I read through Nick's tutorial on authenticating an app with App Engine, but just having the token doesn't get me the uniquely-assigned user ID associated with every Google account on the backend. On top of that, prior experience has taught me the hard way that an app's webview session is incongruous with the app's HTTPClient session. So even if I could log in with Nick's method it wouldn't help me sign into the webviews.
Then I came across this tutorial, which actually seems really promising, but so far I haven't been able to adapt his code to work with my own.
I also found this SO link which suggests that all I need to do is pass the auth token (which I could presumably obtain via Nick's method) into every webview I load as a cookie.
And that's about it. They are all rather different approaches, so I'm wondering if any of them are actually what I want. Or, if somewhere out there a reasonably simple approach actually exists. I'd really appreciate it if someone knows of a straightforward answer on this one. Thank you!
For security reasons WebViews do not have access to the phone's cache, cookie store etc, it is instead recommended you use the new Chrome Custom Tabs which can auto log in your users.
Concerning the "would you like to allow example.appspot.com to use your Google account?" screen; this is the standard OAuth process and requires that the User sign in and allow your app to access their account information.
In your 'example.appspot.com' App Engine app, if you are using an API that requires user information, like the Google Calendar API, it is required that you specifically request the User for their approval to access this information.
Once you have their approval, you can then save the access and refresh tokens to make future API calls on their behalf without the need for repeated user consent. You can see how the entire Oauth flow works in the OAuth 2.0 Playground.
Even if you automatically logged your user in, they will still see the approval page requesting for your app to have access to their information. To develop a hack to forcefully approve the access to a User's information on their behalf is a major security violation.
You can take a look at the new Firebase Authentication flow to easily manage your user's Oauth experience in your App Engine application.

Google Play Services - Clear allowed accounts

When using the new Google Play Services to authenticate an account, you first use the AccountPicker to allow the user to select an account. If the user has not authenticated with your application before, a UserRecoverableAuthException will be thrown which gives you an intent to show the 'Allow Access' page. You only need to allow access one time. However, for testing purposes, I need to be see the Allow Access page every time.
So, does any know how you can clear the permissions for Google Play Services? Or some other method that will show the allow access page every time?
In your Google Account Settings, there's a way to set up application-specific passwords. Sign up for 2-step verification and then you can create them. To temporarily revoke the permission, you can remove or change the password: http://support.google.com/accounts/bin/answer.py?hl=en&answer=1070455
Otherwise, change the password to your entire Google account temporarily.
Unfortunately I don't think there's an easy programmatic way to do this. It seems like quite a serious security flaw that a user/administrator can't revoke Google Account access to an installed app. From what I can tell, Google is fetching the authentication information from a server, and if something in that operation fails, it throws the UserRecoverableAuthException. That's when you normally fire off the Intent from UserException.getIntent(), which contacts the server with a request such as:
scope:oauth2:https://www.googleapis.com/auth/drive.readonly[
account:<your_account>#gmail.com,
scope:oauth2:https://www.googleapis.com/auth/drive.readonly,
extrashash:<some_number>]
Now there's no documentation I've found for instructing the server to revoke that Auth Scope requested above. It might not even be possible. However, you could try to capture the values in the Intent returned by UserException.getIntent() and use it to create a new Intent you launch whenever the user wishes to sign in with their Google account. However, the server might realize the app is already authenticated, and then send you through without the prompt.

Categories

Resources