Created
May 4, 2017 13:33
-
-
Save anonymous/a3703d219fff13eacb91dea4c6caff75 to your computer and use it in GitHub Desktop.
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
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