Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2017 13:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a3703d219fff13eacb91dea4c6caff75 to your computer and use it in GitHub Desktop.
Save anonymous/a3703d219fff13eacb91dea4c6caff75 to your computer and use it in GitHub Desktop.
private static final int PICK_PDF_REQUEST = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showFileChooser();
}
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
startActivityForResult(intent, PICK_PDF_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_PDF_REQUEST && resultCode == RESULT_OK) {
Uri filePath = data.getData();
Log.d("PATH", "onActivityResult: " + filePath);
FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
StorageReference pdfRef = firebaseStorage
.getReference()
.child("pdfs/" + filePath.getLastPathSegment());
pdfRef.putFile(filePath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d("SUCCESS", "onSuccess: Upload succeed");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment