簡體   English   中英

Google 驅動器文件上傳在 Android Webview 中不起作用

[英]Google drive file upload not working in Android Webview

我正在將文件上傳到 WebView。 本地文件運行良好。 但是來自谷歌驅動器的文件不起作用。 本地文件的URI信息不為空。(不為空)

本地文件:content://com.android.providers.downloads.documents/document/xxx

谷歌雲端硬盤文件:content://com.google.android.apps.docs.storage/document/xxx

這是我的代碼。

...
       takeFileResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
            int resultCode = result.getResultCode();


            if (resultCode == RESULT_OK) {
                Intent intent = result.getData();
                Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileChooserDialog.class.getSimpleName());
                if (fragment instanceof DialogFragment) {
                    ((DialogFragment) fragment).dismiss();
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if (null == uploadValueCallBack) {
                        return;
                    }
                    if (intent != null) {
                        Uri uri = intent.getData();
                        intent.setData(uri);
                    }

                    uploadUris = WebChromeClient.FileChooserParams.parseResult(resultCode, intent);
                    uploadValueCallBack.onReceiveValue(uploadUris);
                    uploadValueCallBack = null;

                } else if (null != uploadMessage) {
                    Uri resultUri = (intent == null) ? null : intent.getData();
                    uploadMessage.onReceiveValue(resultUri);
                    uploadMessage = null;
                }

            }


        });
...


       Intent i = new Intent(Intent.ACTION_GET_CONTENT);
       i.addCategory(Intent.CATEGORY_OPENABLE);
                   
       String[] fileMimeTypes = {
                            "application/pdf",
                            "application/zip",
                            "image/*",
                    };
       
       i.setType("*/*");
       i.putExtra(EXTRA_MIME_TYPES, fileMimeTypes);
       takeFileResultLauncher.launch(Intent.createChooser(i, "File Chooser"));


...


我不知道發生這種情況的原因。 也許我必須檢查網頁?

請幫我... :(

我在本地保存了 google 驅動器文件並將該本地 uri 發送到 webview。

Intent intent = new Intent();
intent.setData(Uri.fromFile(savedLocalFile(uri));
WebChromeClient.FileChooserParams.parseResult(resultCode, intent);

savedLocalFile() function 返回存儲在本地(或外部)存儲中的File

如果您有更好的想法,請留下評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM