Skip to content

Android configure via json #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,31 @@ Lastly, due to some dependencies requirements, Firestack supports iOS versions 8

### Android

There are several ways to setup Firebase on Android. The _easiest_ way is to pass the configuration settings in JavaScript. In that way, there is no setup for the native platform.
There are several ways to setup Firebase on Android. The _easiest_ way is to pass the configuration settings in JavaScript. In that way, there is no setup for the native platform.

#### google-services.json setup
If you prefer to include the default settings in the source of your app, download the `google-services.json` file provided by Firebase in the _Add Firebase to Android_ platform menu in your Firebase configuration console.

Next you'll have to add the google-services gradle plugin in order to parse it.

Add the google-services gradle plugin as a dependency in the *project* level build.gradle
`android/build.gradle`
```java
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
```

In your app build.gradle file, add the gradle plugin at the VERY BOTTOM of the file (below all dependencies)
`android/app/build.gradle`
```java
apply plugin: 'com.google.gms.google-services'
```

## Usage

After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String setKeyOrDefault(
final String val = params.getString(key);
Log.d(TAG, "Setting " + key + " from params to: " + val);
return val;
} else if (defaultValue != null && defaultValue != "") {
} else if (defaultValue != null && !defaultValue.equals("")) {
Log.d(TAG, "Setting " + key + " from params to: " + defaultValue);
return defaultValue;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public String getName() {
}

@ReactMethod
public void downloadUrl(final String storageUrl,
public void downloadUrl(final String javascriptStorageBucket,
final String path,
final Callback callback) {
FirebaseStorage storage = FirebaseStorage.getInstance();
String storageBucket = storage.getApp().getOptions().getStorageBucket();
String storageUrl = "gs://"+storageBucket;
StorageReference storageRef = storage.getReferenceFromUrl(storageUrl);
StorageReference fileRef = storageRef.child(path);
StorageReference fileRef = storageRef.child(path);

Task<Uri> downloadTask = storageRef.getDownloadUrl();
Task<Uri> downloadTask = fileRef.getDownloadUrl();
downloadTask.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Expand Down