Android get user data

Get User’s Birthdate & Gender using Google Sign-In Android

I’ve integrated Google Sign-In in my application. I can get user’s Email and DisplayName . Now, I want to get user’s Birthdate and Gender .

I’ve added all required requests & Scopes into GoogleApiClient which all are granted by API. here’s code.

Here’s the granted Scopes in GoogleSignInAccount

Here’s the log of granted scopes

Here’s my Google Mobile Service’s dependency

Now, I don’t know how to get access to user’s profile information .

7 Answers 7

As mentioned in Getting people and profile information, to get additional profile information and a user’s contacts, use the People API. You must get consent from the user to access this information by requesting additional scopes when the user signs in.

You can call people.get , passing in a resource name, to get private contact and public profile data for each person. If your request is successful, the response contains an instance of a Person including birthday and gender.

You may want to visit the links I’ve provided for more information.

Here is the complete working example, hope it help for future reader. What the app do is sign in(Sign In API included name and email) first, then request birthday & gender(People API) authentication, and save it to SharedPreferences for reuse on next launch. Finally it will print basic info and advanced (gender & birthday) info.

Источник

How to store user data using Firebase in Android?

I need to create and use a database entry with all details (uid, name etc) for each user that logs in to the application

I am having trouble storing user data in order to use and retrieve user profile info using Firebase in Android. I found this documentation on the old version of Firebase but this does not seem to work any longer.

Does anyone know how to reproduce the above code so it works with the new version of Firebase? Many thanks in advance.

Edit — code below:

3 Answers 3

For creating user in firebase database (new Version) ,you need to do changes as followning..

now Add following method in onCreate() .

  • To authenticate users with email and password (Google, Facebook) use Firebase Auth
  • To use Firebase database to store different data than use Firebase Realtime Database
  • If you want to Manage Auth users from your backend

User Management — Retrive user’s full data and change a user’s password or email address Custom Authentication — You can integrate an external user system with Firebase. Identity Verification — Use the service to identify these users on your own server.

Firebase Auth has a NODE JS sdk which you can use. If you want to access this features from Android, than you have to create a web service (eg.Restful API) and communicate with it through network.

If you want to access registered Auth users in Realtime Database i dont think you can because they are separated from each other. You can register users in Realtime Database but i dont understund why you want to do that since Auth provides you this feature in an easier way.

Firebase Realtime Database also has an Admin SDK (Java and Node JS)

Источник

How to access data/data folder in Android device?

I am developing an app and I know my database *.db will appear in data/data/com.****.***

I can access this file from AVD in Eclipse with help of sqlite manager

But I can’t access this file in my Android phone.
I googled it and it says I need to root my phone to do it, but I don’t want to do that.

How can I access my data/data/. directory in my Android phone «without rooting it«?

Can I change user permissions for the directory data/data. without rooting it?

18 Answers 18

Accessing the files directly on your phone is difficult, but you may be able to copy them to your computer where you can do anything you want with it. Without rooting you have 2 options:

Читайте также:  Data binding fragment android

If the application is debuggable you can use the run-as command in adb shell

Alternatively you can use Android’s backup function.

You will now be prompted to ‘unlock your device and confirm the backup operation’. It’s best NOT to provide a password, otherwise it becomes more difficult to read the data. Just click on ‘backup my data’. The resulting ‘backup.ab’ file on your computer contains all application data in android backup format. Basically it’s a compressed tar file. This page explains how you can use OpenSSL’s zlib command to uncompress it. You can use the adb restore backup.db command to restore the backup.

If you are using Android Studio 3.0 or later version then follow these steps.

  1. Click View >Tool Windows >Device File Explorer.
  2. Expand /data/data/[package-name] nodes.

You can only expand packages which runs in debug mode on non-rooted device.

You could also try fetching the db using root explorer app. And if that does not work then you can try this:

  1. Open cmd
  2. Change your directory and go into ‘Platform tools’
  3. Type ‘ adb shell ‘
  4. su
  5. Press ‘Allow’ on device
  6. chmod 777 /data /data/data /data/data/com.application.package /data/data/com.application.package/*
  7. Open DDMS view in Eclipse and from there open ‘FileExplorer’ to get your desired file

After this you should be able to browse the files on the rooted device.

To do any of the above (i.e. access protected folders from within your phone itself), you still need root. (That includes changing mount-permissions on the /data folder and accessing it)

Without root, accessing the /data directly to read except from within your application via code isn’t possible. So you could try copying that file to sdcard or somewhere accessible, and then, you should be able to access it normally.

Rooting won’t void your warranty if you have a developer device. I’m sorry, there isn’t any other way AFAIK.

The easiest way (just one simple step) to pull a file from your debuggable application folder (let’s say /data/data/package.name/databases/file ) on an unrooted Android 5.0+ device is by using this command:

  1. Open your command prompt
  2. Change directory to E:\Android\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platform-tools
  3. Enter below commands
  4. adb -d shell
  5. run-as com.your.packagename cat databases/database.db > /sdcard/database.db
  6. Change directory to cd /sdcard to make sure database.db is there.
  7. adb pull /sdcard/database.db or simply you can copy database.db from device .

Use File Explorer in eclipse. Select Windows => Show View => Other . => File Explorer.

An another way is pull the file via adb:

To backup from Android to Desktop

Open command line cmd and run this: adb backup -f C:\Intel\xxx.ab -noapk your.app.package. Do not enter password and click on Backup my data. Make sure not to save on drive C root. You may be denied. This is why I saved on C:\Intel.

To extract the *.ab file

  1. Go here and download: https://sourceforge.net/projects/adbextractor/
  2. Extract the downloaded file and navigate to folder where you extracted.
  3. run this with your own file names: java -jar abe.jar unpack c:\Intel\xxx.ab c:\Intel\xxx.tar

I had also the same problem once. There is no way to access directly the file within android devices except adb shell or rooting device.

Beside here are 02 alternatives:

On a rooted device, the correct solution is this:

The original solution worked, but the chmod would return unknown directory. Changing the chmod command to /data/data/* gave access to all subfolders in the data directory from DDMS in Intellij. I assume the same solution is true for Eclipse DDMS.

UPDATE So, what I’ve found is strange. I’m running a Nexus 6 using DDMS in IntelliJ (Android Device Monitor). I have built a little starter app. Said app saves data to a .csv file in data/data/com.example.myapp/files

When I first started to try to access this file on my Nexus 6, I found that I have to root the device.. I could see the data folder, but trying to open it would not work. As mentioned online in other places, the expand + would vanish then reappear shortly thereafter (note, there are solutions on the web that claim to allow access to these folders without rooting, I didn’t find them till too late, and I’m not sure if I prefer not to root anyway ((I’d rather be able to do it manually than rely on an app or command prompt to give me my solutions))). I rooted my 6 and tried DDMS again.

At this point, it showed me the data folder and I could expand the folder and see the com. directories, but I could not open any of them. That is when I discovered the above solution. The initial instructions would not work on this part:

Читайте также:  Android layout view example

That is when I tried the solution I posted:

That solution seemed to work, but only on certain folders. I now could expand my myapp folder, but could not expand the files directory in it.

At this point, I played around for a while then figured why not just try it on the directory I need rather than trying these wildcard entries.

These commands allowed me to expand and view the files in my app’s directory to confirm that the .csv was being saved correctly.

Hope this helps someone. I struggled with this for hours!

Источник

How to store user data using Firebase in Android?

I need to create and use a database entry with all details (uid, name etc) for each user that logs in to the application

I am having trouble storing user data in order to use and retrieve user profile info using Firebase in Android. I found this documentation on the old version of Firebase but this does not seem to work any longer.

Does anyone know how to reproduce the above code so it works with the new version of Firebase? Many thanks in advance.

Edit — code below:

3 Answers 3

For creating user in firebase database (new Version) ,you need to do changes as followning..

now Add following method in onCreate() .

  • To authenticate users with email and password (Google, Facebook) use Firebase Auth
  • To use Firebase database to store different data than use Firebase Realtime Database
  • If you want to Manage Auth users from your backend

User Management — Retrive user’s full data and change a user’s password or email address Custom Authentication — You can integrate an external user system with Firebase. Identity Verification — Use the service to identify these users on your own server.

Firebase Auth has a NODE JS sdk which you can use. If you want to access this features from Android, than you have to create a web service (eg.Restful API) and communicate with it through network.

If you want to access registered Auth users in Realtime Database i dont think you can because they are separated from each other. You can register users in Realtime Database but i dont understund why you want to do that since Auth provides you this feature in an easier way.

Firebase Realtime Database also has an Admin SDK (Java and Node JS)

Источник

Data and file storage overview

Android uses a file system that’s similar to disk-based file systems on other platforms. The system provides several options for you to save your app data:

  • App-specific storage: Store files that are meant for your app’s use only, either in dedicated directories within an internal storage volume or different dedicated directories within external storage. Use the directories within internal storage to save sensitive information that other apps shouldn’t access.
  • Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files.
  • Preferences: Store private, primitive data in key-value pairs.
  • Databases: Store structured data in a private database using the Room persistence library.

The characteristics of these options are summarized in the following table:

Type of content Access method Permissions needed Can other apps access? Files removed on app uninstall?
App-specific files Files meant for your app’s use only From internal storage, getFilesDir() or getCacheDir()

From external storage, getExternalFilesDir() or getExternalCacheDir()

Never needed for internal storage

Not needed for external storage when your app is used on devices that run Android 4.4 (API level 19) or higher

No Yes
Media Shareable media files (images, audio files, videos) MediaStore API READ_EXTERNAL_STORAGE when accessing other apps’ files on Android 11 (API level 30) or higher

READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE when accessing other apps’ files on Android 10 (API level 29)

Permissions are required for all files on Android 9 (API level 28) or lower

Yes, though the other app needs the READ_EXTERNAL_STORAGE permission No
Documents and other files Other types of shareable content, including downloaded files Storage Access Framework None Yes, through the system file picker No
App preferences Key-value pairs Jetpack Preferences library None No Yes
Database Structured data Room persistence library None No Yes

The solution you choose depends on your specific needs:

How much space does your data require? Internal storage has limited space for app-specific data. Use other types of storage if you need to save a substantial amount of data. How reliable does data access need to be? If your app’s basic functionality requires certain data, such as when your app is starting up, place the data within internal storage directory or a database. App-specific files that are stored in external storage aren’t always accessible because some devices allow users to remove a physical device that corresponds to external storage. What kind of data do you need to store? If you have data that’s only meaningful for your app, use app-specific storage. For shareable media content, use shared storage so that other apps can access the content. For structured data, use either preferences (for key-value data) or a database (for data that contains more than 2 columns). Should the data be private to your app? When storing sensitive data—data that shouldn’t be accessible from any other app—use internal storage, preferences, or a database. Internal storage has the added benefit of the data being hidden from users.

Categories of storage locations

Android provides two types of physical storage locations: internal storage and external storage. On most devices, internal storage is smaller than external storage. However, internal storage is always available on all devices, making it a more reliable place to put data on which your app depends.

Removable volumes, such as an SD card, appear in the file system as part of external storage. Android represents these devices using a path, such as /sdcard .

Apps themselves are stored within internal storage by default. If your APK size is very large, however, you can indicate a preference within your app’s manifest file to install your app on external storage instead:

Permissions and access to external storage

On earlier versions of Android, apps needed to declare the READ_EXTERNAL_STORAGE permission to access any file outside the app-specific directories on external storage. Also, apps needed to declare the WRITE_EXTERNAL_STORAGE permission to write to any file outside the app-specific directory.

More recent versions of Android rely more on a file’s purpose than its location for determining an app’s ability to access, and write to, a given file. In particular, if your app targets Android 11 (API level 30) or higher, the WRITE_EXTERNAL_STORAGE permission doesn’t have any effect on your app’s access to storage. This purpose-based storage model improves user privacy because apps are given access only to the areas of the device’s file system that they actually use.

Android 11 introduces the MANAGE_EXTERNAL_STORAGE permission, which provides write access to files outside the app-specific directory and MediaStore . To learn more about this permission, and why most apps don’t need to declare it to fulfill their use cases, see the guide on how to manage all files on a storage device.

Scoped storage

To give users more control over their files and to limit file clutter, apps that target Android 10 (API level 29) and higher are given scoped access into external storage, or scoped storage, by default. Such apps have access only to the app-specific directory on external storage, as well as specific types of media that the app has created.

Use scoped storage unless your app needs access to a file that’s stored outside of an app-specific directory and outside of a directory that the MediaStore APIs can access. If you store app-specific files on external storage, you can make it easier to adopt scoped storage by placing these files in an app-specific directory on external storage. That way, your app maintains access to these files when scoped storage is enabled.

To prepare your app for scoped storage, view the storage use cases and best practices guide. If your app has another use case that isn’t covered by scoped storage, file a feature request. You can temporarily opt-out of using scoped storage.

View files on a device

To view the files stored on a device, use Android Studio’s Device File Explorer.

Additional resources

For more information about data storage, consult the following resources.

Videos

Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.

Источник

Читайте также:  Что такое windows android linux
Оцените статью