Get list firebase android

List files with Cloud Storage on Android

Cloud Storage for Firebase allows you to list the contents of your Cloud Storage bucket. The SDKs return both the items and the prefixes of objects under the current Cloud Storage reference.

Projects that use the List API require Cloud Storage for Firebase Rules version 2. If you have an existing Firebase project, follow the steps in the Security Rules Guide.

list() uses the Google Cloud Storage List API. In Cloud Storage for Firebase, we use / as a delimiter, which allows us to emulate file system semantics. To allow for efficient traversal of large, hierarchical Cloud Storage buckets, the List API returns prefixes and items separately. For example, if you upload one file /images/uid/file1 ,

  • root.child(‘images’).listAll() will return /images/uid as a prefix.
  • root.child(‘images/uid’).listAll() will return the file as an item.

The Cloud Storage for Firebase SDK does not return object paths that contain two consecutive / s or end with a / . For example, consider a bucket that has the following objects:

  • correctPrefix/happyItem
  • wrongPrefix//sadItem
  • lonelyItem/

The list operations on items in this bucket will give the following results:

  • The list operation at the root returns the references to correctPrefix , wrongPrefix and lonelyItem as prefixes .
  • The list operation at the correctPrefix/ returns the references to correctPrefix/happyItem as items .
  • The list operation at the wrongPrefix/ doesn’t return any references because wrongPrefix//sadItem contains two consecutive / s.
  • The list operation at the lonelyItem/ doesn’t return any references because the object lonelyItem/ ends with / .

List all files

You can use listAll to fetch all results for a directory. This is best used for small directories as all results are buffered in memory. The operation also may not return a consistent snapshot if objects are added or removed during the process.

For a large list, use the paginated list() method as listAll() buffers all results in memory.

The following example demonstrates listAll .

Kotlin+KTX

Paginate list results

The list() API places a limit on the number of results it returns. list() provides a consistent pageview and exposes a pageToken that allows control over when to fetch additional results.

The pageToken encodes the path and version of the last item returned in the previous result. In a subsequent request using the pageToken, items that come after the pageToken are shown.

The following example demonstrates paginating a result:

Kotlin+KTX

Handle errors

list() and listAll() fail if you haven’t upgraded the Security Rules to version 2. Upgrade your Security Rules if you see this error:

Other possible errors may indicate the user does not have the right permission. More information on errors can be found in the Handle Errors.

Читайте также:  Сдвиг экрана вправо андроид

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Источник

Firebase [Android] Get list from database to map?

A User in my Firebase database can have friends, that are other Users. Here is how it is structured:

I want to load the friendlist part into a map and then load it into a recyclerview . This is from my Fragment:

Here is the other classes:

When I run the app, the recyclerview is empty. Any suggestion what I might need to do here?

EDIT:

I get this warning:

In my Firebase database rules, I have set the rules under /users to allow read if auth != null and write if $uid == auth.uid

2 Answers 2

For load data you must create

Then get list from User and create list. But with FirebaseRecyclerAdapter you give a list of users!!

If you want to create list of friends fore one user, you need to get query for UserId and get list for adapter.

So, first do not create User class or FriendList class. Just add this, must be work:

Permission denied generally means it is from a rules issue. Try reading the data via Database simulator first to make sure your rules are correctly set up.

And then, as Sergey’s answer. I would try addListenerForSingleValueEvent to retrieve values. And if you need to handle realtime data FirebaseRecyclerAdapter is useful. But if you don’t It’s better to make your own custom recycler adapter. In my case, I use custom recycler adapter for non-realtime and realtime database since FirebaseRecyclerAdapter has some limits.

Источник

Get list of Firebase notifications?

Is there a way to see all the notifications sent via Firebase?

I can’t find anything in the docs or anywhere else.

It’d be cool if it is possible over the console, but HTTP would do as well! Any ideas?

1 Answer 1

Unfortunately, there is no available API as of the moment to retrieve your GCM/FCM logs. However, there’s been a recent improvement in the Firebase Notifications console where stats (sent count only for now) for messages sent using the FCM API is included in the Firebase Notification console stats. From my answer in the similar post:

As of August 2018, stats for messages sent using the FCM API are now visible from the console. From the Cloud Messaging section, click on the Reports tab. From there, you will be able to filter by message type ( notification , data , and all)

It would seem that the Impressions and Opens are still only available for messages sent using the console. But Sends for sure now counts the messages sent using the FCM API.

As you might already know, only notifications sent via the console are visible in the Firebase Console itself. In the left-side panel, just select on the Notifications and you will see the list of Notifications sent using the console.

One approach is also to make use of the Google Play Developer Console, but the app should at least be in Alpha Testing.

Источник

Читайте также:  Планшет с андроидом 2012

Android Firebase get List Data

I am trying to get movies list info in my application.

MainActivity

SingleItem

Application crashes, The object class I made don’t read the info right. I want to store a list of movie object and each object contains the movie info.

3 Answers 3

public no-argument constructor means that you need a constructor with no passing data in it

Also, i see in your list of data from firebase data that your key is first letter uppercase. In this case, you should use @PropertyName annotation. Ex:

Since you have private variables, you can annotate methods and have private variables:

From documatation, you can annotate private variables also, but for me is not working. You can try it.

You need to add the public no-argument constructor need for Firebase in your SingleItem class. Remember, when the Firebase Realtime Database SDK deserializes objects coming from the database, it requires that any objects in use to have a public no-argument constructor that it can use to instantiate the object. Fields in the objects are set by using the public setter methods or direct access to public members.

If you don’t use public no-argument constructor , the SDK doesn’t really know how to create an instance of it. In fact, most serialization libraries will have the same requirement.

Your class should look like this:

See also the added annotations. I have added this annotations because of the difference between your fields from your model class which contains first letter lowercase and the actual key from the database which contains first letter uppercase.

To ge the data from your database, please use the following code:

Источник

Get data with Cloud Firestore

There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries:

  • Call a method to get the data.
  • Set a listener to receive data-change events.

When you set a listener, Cloud Firestore sends your listener an initial snapshot of the data, and then another snapshot each time the document changes.

Example data

To get started, write some data about cities so we can look at different ways to read it back:

Web version 9

Web version 8

Swift
Objective-C

Kotlin+KTX

Python

Python

Node.js
Unity

Get a document

The following example shows how to retrieve the contents of a single document using get() :

Web version 9

Web version 8

Swift
Objective-C

Kotlin+KTX

Python

Python

Node.js
Unity

Source Options

For platforms with offline support, you can set the source option to control how a get call uses the offline cache.

By default, a get call will attempt to fetch the latest document snapshot from your database. On platforms with offline support, the client library will use the offline cache if the network is unavailable or if the request times out.

You can specify the source option in a get() call to change the default behavior. You can fetch from only the database and ignore the offline cache, or you can fetch from only the offline cache. For example:

Web version 9

Web version 8

Swift
Objective-C

Kotlin+KTX

Not supported in the Java SDK.

Python

Not supported in the Python SDK.

Node.js

Not supported in the Node.js SDK.

Not supported in the Go SDK.

Читайте также:  Не открываются странички андроид

Not supported in the PHP SDK.

Unity

Not supported in the Unity SDK.

Not supported in the C# SDK.

Not supported in the Ruby SDK.

Custom objects

The previous example retrieved the contents of the document as a map, but in some languages it’s often more convenient to use a custom object type. In Add Data, you defined a City class that you used to define each city. You can turn your document back into a City object:

To use custom objects, you must define a FirestoreDataConverter function for your class. For example:

Web version 9

To use custom objects, you must define a FirestoreDataConverter function for your class. For example:

Web version 8

Call your data converter with your read operations. After conversion, you can access custom object methods:

Web version 9

Call your data converter with your read operations. After conversion, you can access custom object methods:

Web version 8

Swift

To support automatic type serialization in Swift, your type must conform to the Codable protocol and you must include pod ‘FirebaseFirestoreSwift’ as a dependency of your project.

Objective-C

In Objective-C you must do this manually.

Important: Each custom class must have a public constructor that takes no arguments. In addition, the class must include a public getter for each property.

Kotlin+KTX

Each custom class must have a public constructor that takes no arguments. In addition, the class must include a public getter for each property.

Python

Python

Node.js

Node.js uses JavaScript objects.

Not applicable for PHP.

Unity

Not applicable for Ruby.

Get multiple documents from a collection

You can also retrieve multiple documents with one request by querying documents in a collection. For example, you can use where() to query for all of the documents that meet a certain condition, then use get() to retrieve the results:

Web version 9

Web version 8

Swift
Objective-C

Kotlin+KTX

Python

Python

Node.js
Unity

By default, Cloud Firestore retrieves all documents that satisfy the query in ascending order by document ID, but you can order and limit the data returned.

Get all documents in a collection

In addition, you can retrieve all documents in a collection by omitting the where() filter entirely:

Web version 9

Web version 8

Swift
Objective-C

Kotlin+KTX

Python

Python

Node.js
Unity

Get multiple documents from a collection group

A collection group consists of all collections with the same ID. For example, if each document in your cities collection has a subcollection called landmarks , all of the landmarks subcollections belong to the same collection group. By default, queries retrieve results from a single collection in your database. Use a collection group query to retrieve results from a collection group instead of from a single collection.

List subcollections of a document

The listCollections() method of the Cloud Firestore server client libraries lists all subcollections of a document reference.

Retrieving a list of collections is not possible with the mobile/web client libraries. You should only look up collection names as part of administrative tasks in trusted server environments. If you find that you need this capability in the mobile/web client libraries, consider restructuring your data so that subcollection names are predictable.

Not available in the Web client library.

Swift

Not available in the Swift client library.

Objective-C

Not available in the Objective-C client library.

Not available in the Android client library.

Kotlin+KTX

Not available in the Android client library.

Источник

Оцените статью