### Clone Firebase Quickstart Repository
Source: https://github.com/firebase/quickstart-android/blob/master/dataconnect/README.md
Clone the Android quickstart repository to your local machine. Ensure you have Git installed.
```sh
git clone https://github.com/firebase/quickstart-android.git
```
--------------------------------
### Example issue reporting format
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
When reporting an issue, provide details about what you are trying to achieve, where you have looked for information, and where you expected to find it.
```text
What are you trying to do or find out more about?
Where have you looked?
Where did you expect to find this information?
```
--------------------------------
### Deploy Firebase Cloud Functions
Source: https://github.com/firebase/quickstart-android/blob/master/functions/README.md
Navigate to the `functions` directory, install dependencies, and deploy functions to your Firebase project using the Firebase CLI.
```bash
cd functions
npm install
cd ../
firebase --project=YOUR_PROJECT_ID deploy --only functions
```
--------------------------------
### Firestore Indexing Warning Example
Source: https://github.com/firebase/quickstart-android/blob/master/firestore/README.md
This log message indicates that a Firestore query requires a specific index. Clicking the provided link in the log will take you to the Firebase console to create the necessary index.
```log
com.google.firebase.example.fireeats W/Firestore Adapter: onEvent:error
com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/project/...
```
--------------------------------
### Build project with Gradle
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Ensure all tests pass by building your changes locally using the Gradle wrapper.
```shell
./gradlew build
```
--------------------------------
### Event Listeners for Token Generator
Source: https://github.com/firebase/quickstart-android/blob/master/auth/web/auth.html
Sets up event listeners for the file input and generate button. The 'change' event on the file input triggers the file selection and loading process, while the 'click' event on the generate button initiates the token generation.
```javascript
document.getElementById('file').addEventListener('change', handleFileSelect, false); document.getElementById('go').addEventListener('click', handleGenerateClick, false);
```
--------------------------------
### Insert Movie Data using GQL
Source: https://github.com/firebase/quickstart-android/blob/master/dataconnect/README.md
Run this GQL script within VS Code to populate the Cloud SQL database with movie data. Ensure the Firebase Data Connect VS Code extension is set up.
```gql
mutation InsertMovies {
insertMovie(movie: {title: "The Matrix", director: "The Wachowskis", releaseYear: 1999})
insertMovie(movie: {title: "The Lord of the Rings: The Fellowship of the Ring", director: "Peter Jackson", releaseYear: 2001})
insertMovie(movie: {title: "The Dark Knight", director: "Christopher Nolan", releaseYear: 2008})
}
```
--------------------------------
### List Movies Query using GQL
Source: https://github.com/firebase/quickstart-android/blob/master/dataconnect/README.md
Execute this GQL query in VS Code to verify that movie data has been correctly inserted into the database. This query retrieves all movies.
```gql
query ListMovies {
movies {
id
title
director
releaseYear
}
}
```
--------------------------------
### Load Service Account JSON File
Source: https://github.com/firebase/quickstart-android/blob/master/auth/web/auth.html
This JavaScript function handles file selection and parsing of the service account JSON file. It reads the file content and extracts necessary credentials like private key ID, private key, and client email to enable token generation.
```javascript
function handleFileSelect(evt) { console.log('handleFileSelect', evt); evt.stopPropagation(); evt.preventDefault(); var files = evt.target.files; for (var i = 0; i < files.length; i++) { var f = files[i]; if (f.type == "application/json" || f.name.indexOf(".json") >= 0) { loadJson(f); return; } } console.log("No JSON file found!"); } function loadJson(f) { var reader = new FileReader(); reader.onload = function (_) { data = JSON.parse(reader.result) console.log(data); if (data.type && data.type == "service_account") { kid = data.private_key_id; sPKCS8PEM = data.private_key; sub = data.client_email; document.getElementById("notoken").style.display = "none"; document.getElementById("gettoken").style.display = "block"; document.getElementById("subtext").textContent = "Generating Tokens For " + sub; } else { console.log("Bad file read."); } } reader.readAsText(f) }
```
--------------------------------
### Commit changes with git
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Commit your changes using a descriptive message. The `-a` option automatically stages edited files.
```shell
git commit -a
```
--------------------------------
### Push branch to GitHub
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Push your local branch to your GitHub repository to make it available for a pull request.
```shell
git push origin my-fix-branch
```
--------------------------------
### Rebase and force push changes
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
If changes are suggested, rebase your branch against the master branch and force push to update your pull request.
```shell
git rebase master -i
git push origin my-fix-branch -f
```
--------------------------------
### Create a new git branch
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Before submitting a pull request, create a new git branch for your changes. This helps keep your work isolated.
```shell
git checkout -b my-fix-branch master
```
--------------------------------
### Checkout master branch
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Switch back to the local master branch after your changes have been merged.
```shell
git checkout master -f
```
--------------------------------
### Update local master with upstream changes
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Pull the latest changes from the upstream repository into your local master branch to stay synchronized.
```shell
git pull --ff upstream master
```
--------------------------------
### Generate Firebase Custom Token
Source: https://github.com/firebase/quickstart-android/blob/master/auth/web/auth.html
This JavaScript code generates a custom Firebase authentication token. It requires a service account JSON file to be loaded, which provides the private key and client email. The token is signed using RS256 algorithm and includes user ID, issuer, audience, and expiration.
```javascript
var sub = ""; var sPKCS8PEM = ""; var kid = "" // Generate an ID token and sign it with the private key. function handleGenerateClick(evt) { var uid = document.getElementById('uid').value; if (uid == '') { console.log("Blank uid"); return; } // Header var oHeader = {alg: 'RS256', kid: kid, typ: 'JWT'}; // Payload var oPayload = {}; var tNow = KJUR.jws.IntDate.get('now'); var tEnd = KJUR.jws.IntDate.get('now + 1hour'); oPayload.aud = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"; oPayload.exp = tEnd; oPayload.iat = tNow; oPayload.iss = sub; oPayload.sub = sub; oPayload.user_id = uid; oPayload.scope = "https://www.googleapis.com/auth/identitytoolkit"; var sHeader = JSON.stringify(oHeader); var sPayload = JSON.stringify(oPayload); var sJWT = KJUR.jws.JWS.sign(null, sHeader, sPayload, sPKCS8PEM, 'notasecret'); document.getElementById("tokenbox").textContent = sJWT; console.log(sJWT); document.getElementById("droidbox").textContent = "adb shell am broadcast " + "-a com.google.example.ACTION_TOKEN " + "--es key_token " + sJWT; }
```
--------------------------------
### Remove Intent Filter for Java Messaging Service
Source: https://github.com/firebase/quickstart-android/blob/master/messaging/README.md
If using the Java messaging sample, remove this intent filter from the .kotlin.MyFirebaseMessagingService entry in AndroidManifest.xml to avoid conflicts.
```xml
```
--------------------------------
### Firestore Security Rules
Source: https://github.com/firebase/quickstart-android/blob/master/firestore/README.md
Define access control for your Firestore data. These rules specify who can read, create, update, or delete documents in the 'restaurants' and 'ratings' collections.
```json
service cloud.firestore {
match /databases/{database}/documents {
// Anyone can read a restaurant, only authorized
// users can create or update. Deletes are not allowed.
match /restaurants/{restaurantId} {
allow read: if true;
allow create, update: if request.auth.uid != null;
}
// Anyone can read a rating. Only the user who made the rating
// can delete it. Ratings can never be updated.
match /restaurants/{restaurantId}/ratings/{ratingId} {
allow read: if true;
allow create: if request.auth.uid != null;
allow delete: if request.resource.data.userId == request.auth.uid;
allow update: if false;
}
}
}
```
--------------------------------
### Set Default Notification Channel ID in Manifest
Source: https://github.com/firebase/quickstart-android/blob/master/messaging/README.md
Specify the default notification channel ID in your application's manifest. This is used by FCM if no channel is specified in the message payload. Ensure a channel with this ID is created in your code.
```xml
```
--------------------------------
### Firebase Database Security Rules
Source: https://github.com/firebase/quickstart-android/blob/master/database/README.md
These rules define access control and data validation for the Firebase Database. They specify read and write permissions for different data nodes based on user authentication and data content.
```javascript
{
"rules": {
// User profiles are only readable/writable by the user who owns it
"users": {
"$UID": {
".read": "auth.uid == $UID",
".write": "auth.uid == $UID"
}
},
// Posts can be read by anyone but only written by logged-in users.
"posts": {
".read": true,
".write": "auth.uid != null",
"$POSTID": {
// UID must match logged in user and is fixed once set
"uid": {
".validate": "(data.exists() && data.val() == newData.val()) || newData.val() == auth.uid"
},
// User can only update own stars
"stars": {
"$UID": {
".validate": "auth.uid == $UID"
}
}
}
},
// User posts can be read by anyone but only written by the user that owns it,
// and with a matching UID
"user-posts": {
".read": true,
"$UID": {
"$POSTID": {
".write": "auth.uid == $UID",
".validate": "data.exists() || newData.child('uid').val() == auth.uid"
}
}
},
// Comments can be read by anyone but only written by a logged in user
"post-comments": {
".read": true,
".write": "auth.uid != null",
"$POSTID": {
"$COMMENTID": {
// UID must match logged in user and is fixed once set
"uid": {
".validate": "(data.exists() && data.val() == newData.val()) || newData.val() == auth.uid"
}
}
}
}
}
}
```
--------------------------------
### Delete local branch
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
Remove the local feature branch after it has been merged and deleted from the remote repository.
```shell
git branch -D my-fix-branch
```
--------------------------------
### Delete remote branch on GitHub
Source: https://github.com/firebase/quickstart-android/blob/master/CONTRIBUTING.md
After your pull request is merged, you can safely delete your feature branch from the remote GitHub repository.
```shell
git push origin --delete my-fix-branch
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.