-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add upload and download, commit for testing
- Loading branch information
Ray
committed
May 17, 2020
1 parent
27b0a15
commit cfe2ecb
Showing
10 changed files
with
495 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "647410336329", | ||
"firebase_url": "https://fir-storageapi-40a48.firebaseio.com", | ||
"project_id": "fir-storageapi-40a48", | ||
"storage_bucket": "fir-storageapi-40a48.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:647410336329:android:55120c64ce063dae047598", | ||
"android_client_info": { | ||
"package_name": "com.mshlab.FirebaseStorageAPI_sample" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "647410336329-3oj7jdqreaig68sgnm2il9he9359us7r.apps.googleusercontent.com", | ||
"client_type": 1, | ||
"android_info": { | ||
"package_name": "com.mshlab.FirebaseStorageAPI_sample", | ||
"certificate_hash": "f9c28fd349f4fb995b3b114459664cebea06e1dc" | ||
} | ||
}, | ||
{ | ||
"client_id": "647410336329-g2v3c015o54ttjm4heq88sp3qdsri7ca.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyCsiILtWexjRz4xx7ET7HFQ5cJgjxXhZxk" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "647410336329-g2v3c015o54ttjm4heq88sp3qdsri7ca.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:647410336329:android:640edfbb6fe39be9047598", | ||
"android_client_info": { | ||
"package_name": "com.mshlab.mainactivity" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "647410336329-kn1pi9cuaal2otksvrelml2odm4ssu2g.apps.googleusercontent.com", | ||
"client_type": 1, | ||
"android_info": { | ||
"package_name": "com.mshlab.mainactivity", | ||
"certificate_hash": "f9c28fd349f4fb995b3b114459664cebea06e1dc" | ||
} | ||
}, | ||
{ | ||
"client_id": "647410336329-g2v3c015o54ttjm4heq88sp3qdsri7ca.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyCsiILtWexjRz4xx7ET7HFQ5cJgjxXhZxk" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "647410336329-g2v3c015o54ttjm4heq88sp3qdsri7ca.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 75 additions & 1 deletion
76
app/src/main/java/com/mshlab/FirebaseStorageAPI_sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,92 @@ | ||
package com.mshlab.FirebaseStorageAPI_sample; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.google.android.gms.tasks.OnCompleteListener; | ||
import com.google.android.gms.tasks.OnSuccessListener; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.firebase.storage.FileDownloadTask; | ||
import com.google.firebase.storage.FirebaseStorage; | ||
import com.google.firebase.storage.StorageReference; | ||
import com.mshlab.firebasestorageapi.FirebaseStorageAPI; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private String TAG = "MainActivity"; | ||
File localFile; | ||
private InputStream inputStream; | ||
FirebaseStorageAPI firebaseStorageAPI; | ||
TextView statusTextView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
FirebaseStorageAPI.showToast(this,"Hello World"); | ||
statusTextView = findViewById(R.id.statusTextView); | ||
firebaseStorageAPI = new FirebaseStorageAPI.Builder() | ||
.setVisibleAcitivty(this) | ||
.allowCancel(false).build(); | ||
|
||
try { | ||
inputStream = this.getAssets().open("pic.png"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
try { | ||
localFile = File.createTempFile("images", "jpg"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
} | ||
|
||
public void downloadButton(View view) { | ||
StorageReference mStorageRef = FirebaseStorage.getInstance().getReference().getRoot().child("sample.png"); | ||
firebaseStorageAPI.downloadToLocalPath(mStorageRef, localFile, new OnCompleteListener<FileDownloadTask.TaskSnapshot>() { | ||
@Override | ||
public void onComplete(@NonNull Task<FileDownloadTask.TaskSnapshot> task) { | ||
if (task.isComplete()) { | ||
Log.e(TAG, "Stream Size: " + localFile.length()); | ||
statusTextView.setText("file downloaded successfully\n Size: " + localFile.length() + " Byte"); | ||
|
||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
public void uploadButton(View view) { | ||
final StorageReference mStorageRef = FirebaseStorage.getInstance().getReference().getRoot().child("sample.png"); | ||
firebaseStorageAPI.upload(inputStream, mStorageRef, new OnCompleteListener() { | ||
@Override | ||
public void onComplete(@NonNull Task task) { | ||
if (task.isSuccessful()) { | ||
mStorageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { | ||
@Override | ||
public void onSuccess(Uri uri) { | ||
statusTextView.setText("file uploaded successfully\n File URL: " + uri.toString()); | ||
|
||
|
||
} | ||
}); | ||
|
||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
android:onClick="uploadButton" | ||
android:layout_marginBottom="16dp" | ||
android:text="download file"></Button> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:onClick="downloadButton" | ||
android:text="upload file"></Button> | ||
|
||
<TextView | ||
android:id="@+id/statusTextView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="32dp" | ||
android:gravity="center" | ||
android:text="Ready to upload or download" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"></TextView> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.