Skip to content

Commit 9c0c728

Browse files
authored
Merge pull request #56 from devshackio/android-configure-via-json
Android configure via json
2 parents e754101 + bb57110 commit 9c0c728

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,31 @@ Lastly, due to some dependencies requirements, Firestack supports iOS versions 8
200200

201201
### Android
202202

203-
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.
203+
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.
204204

205+
#### google-services.json setup
205206
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.
206207

208+
Next you'll have to add the google-services gradle plugin in order to parse it.
209+
210+
Add the google-services gradle plugin as a dependency in the *project* level build.gradle
211+
`android/build.gradle`
212+
```java
213+
buildscript {
214+
// ...
215+
dependencies {
216+
// ...
217+
classpath 'com.google.gms:google-services:3.0.0'
218+
}
219+
}
220+
```
221+
222+
In your app build.gradle file, add the gradle plugin at the VERY BOTTOM of the file (below all dependencies)
223+
`android/app/build.gradle`
224+
```java
225+
apply plugin: 'com.google.gms.google-services'
226+
```
227+
207228
## Usage
208229

209230
After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:

android/src/main/java/io/fullstack/firestack/FirestackModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public String setKeyOrDefault(
6666
final String val = params.getString(key);
6767
Log.d(TAG, "Setting " + key + " from params to: " + val);
6868
return val;
69-
} else if (defaultValue != null && defaultValue != "") {
69+
} else if (defaultValue != null && !defaultValue.equals("")) {
7070
Log.d(TAG, "Setting " + key + " from params to: " + defaultValue);
7171
return defaultValue;
7272
} else {

android/src/main/java/io/fullstack/firestack/FirestackStorage.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ public String getName() {
6060
}
6161

6262
@ReactMethod
63-
public void downloadUrl(final String storageUrl,
63+
public void downloadUrl(final String javascriptStorageBucket,
6464
final String path,
6565
final Callback callback) {
6666
FirebaseStorage storage = FirebaseStorage.getInstance();
67+
String storageBucket = storage.getApp().getOptions().getStorageBucket();
68+
String storageUrl = "gs://"+storageBucket;
6769
StorageReference storageRef = storage.getReferenceFromUrl(storageUrl);
68-
StorageReference fileRef = storageRef.child(path);
70+
StorageReference fileRef = storageRef.child(path);
6971

70-
Task<Uri> downloadTask = storageRef.getDownloadUrl();
72+
Task<Uri> downloadTask = fileRef.getDownloadUrl();
7173
downloadTask.addOnSuccessListener(new OnSuccessListener<Uri>() {
7274
@Override
7375
public void onSuccess(Uri uri) {

0 commit comments

Comments
 (0)