microsoft / WSA

Developer-related issues and feature requests for Windows Subsystem for Android
MIT License
1.45k stars 798 forks source link

Error when sharing a file with name starting with "Con" #526

Open massimobio opened 4 months ago

massimobio commented 4 months ago

Steps to reproduce

I can share files in PDF, XML, WAV and other formats from my app and it all works correctly except when the name of the file starts with the letters "Con", in which case I get the error:

Screenshot 2024-02-02 170708

For example, sharing Connection.pdf fails while sharing Comnection.pdf works and the file appears in the Windows Downloads folder. 100% reproducible on various Windows machines. Only affects Windows. Android devices work as expected.

My share code:

        fun share(context: Context, uri: Uri, type: String, title: String) {
            val shareIntent = Intent(Intent.ACTION_SEND)
            shareIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, title)
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
            shareIntent.type = type

            val chooser = Intent.createChooser(shareIntent, context.resources.getString(R.string.share))

            context.packageManager.queryIntentActivities(chooser, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))

            for (resolveInfo in resInfoList) {
                val packageName = resolveInfo.activityInfo.packageName
                context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION)
            }
            context.startActivity(chooser)
        }

✔️ Expected Behavior

The file to be downloaded to the Windows Downloads folder.

❌ Actual Behavior

I get an error: Windows couldn't download file. The file name, directory name or volume label syntax is incorrect.

Other Software

No response

Please specify the version of Windows Subsystem for Android

2311.40000.5.0