Search code examples
javaandroidfilechooser

Image chooser close on swipe down on Android


The image selection window closes when I swipe down, I'd like to turn this off but I can't find any documentation.

I have one function for selecting files and images. When I open the file selection, a window appears that does not close with a swipe, and when I select images, another window appears that can be minimized with a swipe down. This irritates users of the application. Tell me, is it possible to disable this? screenshot

My code

 webAppView.setWebChromeClient(new WebChromeClient() {
            public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
                callback.invoke(origin, true, false);
            }
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){
                mUploadMessage = uploadMsg;
                String[] types = {acceptType};
                openImageChooser(types);
            }

            // For Lollipop 5.0+ Devices

            public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                mUploadMessages = filePathCallback;
                //Log.d("file", Arrays.toString(fileChooserParams.getAcceptTypes()));
                openImageChooser(fileChooserParams.getAcceptTypes());
                return true;
            }


            //openFileChooser for other Android versions

            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                openFileChooser(uploadMsg, acceptType);
            }

            private void openImageChooser(String[] types_array) {
                try {
                    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                    i.addCategory(Intent.CATEGORY_OPENABLE);

                    i.setType("*/*");
                    i.putExtra(Intent.EXTRA_MIME_TYPES, types_array);

                    i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                    Intent chooserIntent = Intent.createChooser(i, "Files Chooser");

                    startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public void onProgressChanged(WebView view, int progress) {
                if (progress == 100) {
                    preload_img.setVisibility(View.INVISIBLE);
                }
            }

        });

and

@Override
    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Uri[] results = null;
        try {
            if (resultCode != RESULT_OK) {
                results = null;
            } else {
                if (data != null) {
                    String dataString = data.getDataString();
                    ClipData clipData = data.getClipData();
                    if (clipData != null) {
                        results = new Uri[clipData.getItemCount()];
                        for (int i = 0; i < clipData.getItemCount(); i++) {
                            ClipData.Item item = clipData.getItemAt(i);
                            results[i] = item.getUri();
                        }
                    }
                    if (dataString != null) {
                        results = new Uri[]{Uri.parse(dataString)};
                    }
                } else {
                    results = new Uri[]{mCapturedImageURI};
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        mUploadMessages.onReceiveValue(results);
        mUploadMessages = null;
    }

manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">



    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyDudes"
        android:usesCleartextTraffic="true"
        android:requestLegacyExternalStorage="true"
        tools:targetApi="31">
        <activity
            android:name="ru.my_dudes.mydudesapp.MainActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:launchMode="singleTop">
            <tools:validation testUrl="https://myapp.app/" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="https" />
                <data android:host="myapp.app" />
            </intent-filter>
        </activity>

        <service
            android:name="ru.my_dudes.mydudesapp.ForegroundGpsService"
            android:enabled="true"
            android:exported="false"
            android:foregroundServiceType="location"
            android:stopWithTask="false"></service>
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
    </application>

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
</manifest>

Solution

  • When I open the file selection, a window appears that does not close with a swipe

    It does that on the particular device(s) that you are testing. The behavior of this Intent will vary by device model, and there are tens of thousands of device models.

    Tell me, is it possible to disable this?

    There are no documented Intent extras that control this behavior for ACTION_GET_CONTENT, sorry.

    You might consider switching to a more modern approach and see if you like the results better.