Android Question apk with # char in filename will fail to install

frapel

Active Member
Licensed User
Longtime User
Hello to everybody,
I've already searched the forum but I didn't find a solution.

As the title of this thread, executing the following code will fail to install the apk programmatically in the first case while will work in the second case.

B4X:
Dim intent1 As Intent
' this apk will fail to install (while manually install with a file manager will work)...
intent1.Initialize(intent1.ACTION_VIEW, "file:///sdcard/sample#fail.apk")
intent1.SetType("application/vnd.android.package-archive")
intent1.WrapAsIntentChooser("")
StartActivity(intent1)

' ...but if we remove # it will install without errors !!!
intent1.Initialize(intent1.ACTION_VIEW, "file:///sdcard/sampleok.apk")
intent1.SetType("application/vnd.android.package-archive")
intent1.WrapAsIntentChooser("")
StartActivity(intent1)

How can we handle properly apk filenames with # or similar chars (assuming we can't remove the # char) ?

Thank you in advance for your support. :D
Francesco
 

frapel

Active Member
Licensed User
Longtime User
Hi NJDude and thank you for your reply.

I've tried something like this but with no success:

B4X:
Dim su As StringUtils
Dim uri As String
uri = su.EncodeUrl("file:///sdcard/sample#fail.apk", "UTF-8")
'and then trying to install with the above code but does not work
'...

I don't know if I'm doing something wrong there...
 
Upvote 0

frapel

Active Member
Licensed User
Longtime User

Hi Manfred,
thank you for your info.


I know some chars may create problems and some others are completely not allowed by the file system.

But my question is: why if I try to install the apk with # (an allowed char for files and dirs by Android file system)
it will fail by B4A code and instead it will work with no problems if the installation is done by manually launching the same apk with a file manager ?
 
Upvote 0

frapel

Active Member
Licensed User
Longtime User
URL encode just the FILENAME not the whole line, but I doubt it will work # is not a "legal" character.

Thank you NJDude I will try your suggestion and I will post here the result.

In the meanwhile, may I ask you what do you mean with "# is not a "legal" character" ? On all my Android device (os versions from 2.x to 4.x) I'm allowed to have files with # inside their names... please try to rename a file of yours inserting a # in the name and let me know.

Thank you again
Francesco
 
Upvote 0

frapel

Active Member
Licensed User
Longtime User
I tried your code but doesn't work as you can see in the attached screenshot.

Also attached the whole B4A project to run and confirm the error (before executing the app a sample#fail.apk must be present in DirDefaultExternal)...
 

Attachments

  • charstest.zip
    6.6 KB · Views: 227
  • parse error.png
    parse error.png
    37.3 KB · Views: 268
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Your example doesn't include any file to install, look at the attached project.

Also, your code has the manifest as read-only, I re-wrote it and as you will see, it works.
 

Attachments

  • InstallSample.zip
    234.5 KB · Views: 261
Upvote 0
Top