Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gdrive link must be share
- ###########
- public static String getFinalUrl(String pdfUrl) {
- String documentId = getDocumentId(pdfUrl);
- pdfUrl = "https://drive.google.com/uc?export=download&id=" + documentId;
- return pdfUrl;
- }
- public static String getDocumentId(String pdfUrl) {
- int beginIndex = "https://drive.google.com/file/d/".length();
- int endIndex = pdfUrl.lastIndexOf('/');
- if (endIndex < 0) {
- endIndex = pdfUrl.length();
- }
- String documentId;
- try {
- documentId = pdfUrl.substring(beginIndex, endIndex);
- } catch (StringIndexOutOfBoundsException e) {
- e.printStackTrace();
- return "";
- }
- return documentId;
- }
- ===================
- usage =
- getFinalUrl("https://drive.google.com/file/d/1yqZtxX3YYpVOkqzvukg4-hGA6cwac5oJ/view?usp=share_link");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement