Android get google account name that install package - android

Every application is installed using some google account. I need to know is there a way to retrieve user's google account name with which he installed a specific app.
E.g. Instagram was installed using account A and Facebook using account B. I need to know these A and B.

As far as the google docs shows there are no user-accessible logs or other data on the app installation history. But you can do check the list of all the apps a user have installed on any device but wihtout any installation or uninstallation dates. Just get access to the user google account and you can see the list from this url : APPS. Not sure if there is an API for that tho.
EDIT
in order to get all accounts on the device you can use AccountManger something like AccountManager.getAccounts of course you need a permission for that <uses-permission android:name="android.permission.GET_ACCOUNTS" /> and then iterate over the accounts get the list of apps and search for your specific app(s)

Related

Android Account Manager not detecting package type

I have an Android SDK and I want to use Account Manager to centralise my accounts. The SDK will create an account if the device is registered the first time, if not, it will reuse the same account from the Account Manager.
Issue: If I install 2 apps from my own PC. I can see that the first account is created and is reused by the second app. However, when I install 2 apps from different PC's. The second app is not able to detect the account created by the first app and throws an error
java.lang.SecurityException: uid 10413 cannot explicitly add accounts of type: com.example
In the second scenario, I can see other accounts on the device like Google, Skype, and Whatsapp which are ofcourse not installed from my PC and have a different signature as well then how come these package names and types are visible and not mine?
Resolved: I was using read contact permission but was missing write contact permission.
At a time only one app can register for adding account of a type.
The app that add accounts and the app that need account need to be of same signature. when you are trying from same PC, same debug signature is getting applied so you are able to access.
Or set visibility for packages of other apps that want to access the account while adding the accounts or after adding the account. see method - AccountManager.addAccountExplicitly or setAccountVisibility

Android multi-user: get current user info

Strangely there isn't a question on SO regarding this topic. At least I couldn't find one.
Like Windows & Linux, Android too allows us to have multiple user accounts on the same device/computer:
Each user is the FIRST (or primary) Google account with which the device/user partition was activated. Hence, one way to get the name/email associated with this user is through Google Sign-In:
My question is, is there a way to get at least the name (if not the
email) of the device user? Without using Google Sign-In, which
requires both the Play Services library and the GET_ACCOUNTS permission?
There should be some Android API or Provider that tells us the name of the current device user. I've already looked at the following documents:
Supporting Multiple Users
Manage multiple users
AccountManager
.... and I couldn't find anything there.
Does anyone know of a way to get the name/email of the primary Google account on the current user/partition? WITHOUT Google Sign-In, which requires Play Services? Is there some Java/Android API that gives us the account details for the current user?
Related:
1. How to get active account Id in android multi user
2. How Gmail does it
3. Getting it without the GET_ACCOUNTS permission
4. Getting Android owner's email address nicely

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.

Single Android Account for multiple apps

in my company, we have two apps that access an authentication (from our own webservice) token from the android account manager. Because this is a SSO, we decided to extract the login (activity and AbstractAccountAuthenticator) into a library, that both apps are binding to.
In order to keep the account in the android system, if one of our apps gets uninstalled (assuming the user installed both of our apps), we gave the accountType a unified name ex. my.company.auth (both apps however have the package name my.company.a and my.company.b respectively).
The problem lies when both of our apps gets uninstalled: the entry in the account settings in android is still there.
Does anyone know why or what I am doing wrong?
Does it have to do with the accountType, that has a different 'package name' then the apps?
Thank you very much in advance
You need to separate your custom account type component and provide a separate apk file.
When user tries to use any of your app, you need to check if custom account type app exsits on the device or not.
If your account type app doesn't exist, direct user to playstore for downloading your custom account type app so that user can create account for your custom account type and continue to use your app.
In this way, since user created account is not tied to one app and custom account type is separate app, uninstalling any of your app won't delete account created for your custom account type.

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.

Categories

Resources