Android Question FileProvider is forcing recipient apps to become default apps

JackKirk

Well-Known Member
Licensed User
Longtime User
I am on Android 5.0

I launch the stock standard FileProvider example from https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#content

I tap [View Image] button and get presented with a "Open with" pop up menu.

I tap [Gallery] and B4A image appears.

I close app

I launch the FileProvider example again and then tap [View Image]

This time I do not get the "Open with" pop up menu - B4A image appears immediately.

Back in Android.

[Settings] > [Application manager] > [Gallery] - I see "Set as default" is saying "Set as default"

[Set as default] > says "This app is set to open by default for some actions" > [CLEAR DEFAULTS]

Now I when I launch FileProvider example it works as per first time - i.e. I get the "Open with" pop up menu.

But the sequence repeats...

This is a show stopper for me...
 

JohnC

Expert
Licensed User
Longtime User
I haven't used that example in a while, so I could have this wrong...

But, the first time the "Open With" dialog is displayed, there should be two options at the bottom of that dialog:

"Always" and "Just Once"

If you click the "Always" button, then you will get the results you are seeing because "Always" will "Set as the default".

However, if you select "Once", then it will NOT select a default, so the next "Open With" should again display multiple choices.

NOTE: And if I am wrong with this, then look at the code that initiates the "Open With" dialog - maybe you can see where it might be automatically setting the chosen selection as the default and you can remove that code.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
But, the first time the "Open With" dialog is displayed, there should be two options at the bottom of that dialog:

"Always" and "Just Once"
John,

This does not happen with me - but it could just be Android 5.0

Thanks for your interest...
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Please provide a link to the example project you are using or post the code here in the sub that displays the dialog so I can take a quick look at it.

There may be a way to modify the intent so it wont set the selection as a default.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
As I suspected, it should show the "Always" and "Just Once" buttons.

I have no idea why you don't see those choices.

This is a screen shot of my Samsung S4 running Android 5.0.1 after clicking the "View Image" button.

fp-small.png
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Just a hunch, but when that dialog does appear, do you see any other apps besides "Gallery" in that dialog?

Maybe android is setting "Gallery" as the default without displaying those buttons if gallery is the only app that can currently handle that intent on your device (so it doesn't bother to display those buttons)

But if you later install another image viewing app, then it will display those buttons because then there is then a reason to do so. (because more then one app can handle the intent and so now you have to choose)
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I see that you liked my previous post, but was that the reason the buttons didn't show?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Just a hunch, but when that dialog does appear, do you see any other apps besides "Gallery" in that dialog?
John,

Attached is a screen shot - there are no "JUST ONCE ALWAYS" buttons - my suspicion is still that it is just Android 5.0

Screenshot_2021-02-19-16-08-27.png

Regards...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
It simply means there is no other application that is associated with picture except the gallery app
This only happens after I tap Gallery the first time then go to subsequently click View Image

When Gallery is tapped the first time the Gallery app is being made the default app for .png

This is bad - in a user environment it would be very negative for any app that did this.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Wow - I'm at a loss of whats going wrong.

The screenshot I posted with the buttons was on a Android 5.x device. So, I don't know why your 5.x does not show them.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
You are 5.0.1 right? - I am literally 5.0
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I have a sort of solution - if the btnViewImage_Click code is modified by adding the line [in.WrapAsIntentChooser("Share via")] then I get a "Share via" pop-up everytime I tap [View image].
btnViewImage_Click:
Sub btnViewImage_Click
    Dim FileName As String = "b4a.png"
    File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
    Dim in As Intent
    in.Initialize(in.ACTION_VIEW, "")
    Starter.Provider.SetFileUriAsIntentData(in, FileName)
    'Type must be set after calling SetFileUriAsIntentData
    in.SetType("image/*")
    in.WrapAsIntentChooser("Share via")
    StartActivity(in)
End Sub
HOWEVER if I tap [Gallery] as the recipient app it is still being made the default app for .png - which is BAD

Is this the experience of anyone on an Android > 5.0?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Curious,

What is the "android:targetSdkVersion="xx"" set to in your manifest?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
What is the "android:targetSdkVersion="xx"" set to in your manifest?
The manifest in use is the one that was in the example:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)

AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
CreateResource(xml, provider_paths,
<files-path name="name" path="shared" />
)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The manifest in use is the one that was in the example:
Just for kicks, try changing the targetSdk to "21" and see if that changes anything:

B4X:
 android:targetSdkVersion="21"

Also, Android 5.0 is kind of old - if this issue is only with android 5.0 and does not happen with any higher version of android, will that effect a significant number of your users?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Just dug up an Android 7.0 phone and ran the original example (without my added line as per post #14).

It displays a "Open with" pop-up panel every time - but without "JUST ONCE/ALWAYS" buttons

And if I tap [Gallery] as the recipient app it is still being made the default app for .png - which in my view is BAD

So it seems the pop-up panel behaviour is a function of Android version but (to my limited testing anyrate) the "default app" bug (or whatever you want to call it) is persistent.

Be interested to find out if someone with a latest and greatest Android version could test this to see if it still occurs...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Just for kicks, try changing the targetSdk to "21" and see if that changes anything:
Tried this on my Android 5.0 with the exact same results as in post #1
 
Upvote 0
Top