Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Opening files in the default application #601

Closed
KSemenenko opened this issue Nov 3, 2018 · 12 comments
Closed

Opening files in the default application #601

KSemenenko opened this issue Nov 3, 2018 · 12 comments
Labels
feature-request A request for a new feature. in-progress Actively being worked on.
Milestone

Comments

@KSemenenko
Copy link

The idea is to provide a method for opening files in the application by default.
For example, in my application I need to download files of different types, for example pdf, docx, pictures, and I’ll like to be able to open them with applications already installed, for example Acrobat for pdf, but for the system to choose.

@Redth Redth added the need-more-information Need more information to investigate a bug or proposal label Nov 26, 2018
@Redth
Copy link
Member

Redth commented Nov 26, 2018

I'm not sure exactly what you mean by this. We have Launcher.OpenAsync https://docs.microsoft.com/en-us/xamarin/essentials/launcher

Could you describe a bit more which API's you are suggesting this would use natively on iOS/Android?

@gsmental
Copy link

@Redth sir, suppose i wanted to open PDF file in my app. but I and android have no default component to handle PDF, so when user open any file, it should be open in default application(or suggestion of apps, if multiple.) like as below

extensions
pdf - Acrobate, google view
docs - ms-word, wps office
xlsx - ms-excel, any other app, when can view/edit xlsx files.

@KSemenenko
Copy link
Author

@Redth as written by @gsmental when we need to open some files (for example, pdf, docx ...) we would like to give the user a choice of which program he can open the file with.

Something like in this link: https://forums.xamarin.com/discussion/103042/how-to-open-pdf-or-txt-file-in-default-app-on-xamarin-forms

@draudrau
Copy link

draudrau commented Nov 27, 2018

I would like to add some precision to this request.
In my case, I try to open a local document (image or PDF file) with the launcher and using the scheme "file://".
Doing this, I get an Exception on Android device :
Android.OS.FileUriExposedException

Is there a way to do that : open a local file with the appropriate application ?

Before that, I managed this situation with platforme specific code, like for Android :
Android.App.Application.Context.StartActivity(intent);

@Redth Redth removed the need-more-information Need more information to investigate a bug or proposal label Nov 27, 2018
@Redth
Copy link
Member

Redth commented Nov 27, 2018

I think this is more about the file provider work we are doing.

My understanding of the use case is that you really just want to show the platform's native 'share' dialog to let the user pick how to handle a given file. On android that exception is likely due to the fact you are giving a private file path. This is the work we are doing around using a file provider on android (See #130).

The idea would be you give the API any file path that you want to share, it will run it through the file provider on android to generate a shareable uri, and then we'd use the native share dialog (so on Android it would pretty much be launching an intent - we might need to discuss how things like content type are inferred or set for this).

I'm thinking this issue is really a duplicate of #425

Anybody see a reason this should be kept separate and open? If no objections I'm going to close this one as a duplicate...

@Redth Redth added the need-more-information Need more information to investigate a bug or proposal label Nov 27, 2018
@gsmental
Copy link

it should be separate reason being, we are not sharing any content with any other app like whatsapp. but we are sending url into another app to handle the activity. if android api version is <=23 then there is no issue. but in upper version of >=24, android has changed some security policies for opening file

https://medium.com/@ali.muzaffar/what-is-android-os-fileuriexposedexception-and-what-you-can-do-about-it-70b9eb17c6d0

https://proandroiddev.com/sharing-files-though-intents-are-you-ready-for-nougat-70f7e9294a0b

issue is that when we try to access private path with (other app), other app has no permission.
someone was suggestion copy and paste in public path (which is given for open to another app)

@draudrau
Copy link

I don't think it is a duplicate of #425
I think we are in the same way than the Media Plugin from James Montemagno.

I don't need to share data with other application. I just want to see the file content with the right default application.

@Redth Redth removed the need-more-information Need more information to investigate a bug or proposal label Nov 28, 2018
@Redth
Copy link
Member

Redth commented Nov 29, 2018

Perhaps the nomenclature is the problem here. I think this is still technically 'sharing' data with another application, it's just 'sharing' a file that you want another application to open.

So take the case I have a PDF file that I want to let the user display. On android I basically create an intent with an ACTION_VIEW and let the OS figure out which activities can handle the content type I'm 'sharing'. This is what our 'sharing' API is really being designed to do.

I'm still not convinced this is a separate issue from #425

As for @gsmental yes, > API 23 requires a different way of sharing a file due to security, and this is the work we are doing in #130 which will be used by the sharing API.

@Redth Redth added the need-more-information Need more information to investigate a bug or proposal label Nov 29, 2018
@Redth
Copy link
Member

Redth commented Dec 15, 2018

We are closing this issue since no response was received. Please open a new issue referring to this one if you have more information.

@manuelvalenzuela
Copy link

manuelvalenzuela commented Feb 25, 2019

Hi everyone! In my case (Android experience) when an application have the ability to work with files (for example Slack, Whatsapp, etc), if I want to open a file for some reason, the app shows me one of the two following options:
a) Open the file using one of my installed apps intended to do that.
or
b) The app prompt me a message to explain me that I don't have any app that can open the file.

A few images explains the required feature very well (I have PDF viewer but not DOCX viewer)

screenshot_20190225-154534

screenshot_20190225-154804

screenshot_20190225-155845

@Redth Redth removed the need-more-information Need more information to investigate a bug or proposal label Feb 26, 2019
@jamesmontemagno jamesmontemagno added the feature-request A request for a new feature. label Mar 11, 2019
@DennisWelu
Copy link

I agree with those that see this is a separate issue from what the Share functionality gives you currently. It is sharing in a sense as @Redth points out, but when you Share.RequestAsync the file gets looked at as a file and you get certain options for a file generically speaking. If you instead were to tap on that file in the built-in file browser for your system you would get a different set of options or it would automatically open (because you've previously associated that file type with an app). In that case it looks more at the file extension, e.g. PDF or DOCX or whatever, to determine what to let the user choose from or to launch.

@jamesmontemagno jamesmontemagno added this to the 1.1.1 milestone Apr 1, 2019
@jamesmontemagno
Copy link
Collaborator

Basically: #425

@jamesmontemagno jamesmontemagno added the in-progress Actively being worked on. label Apr 27, 2019
@jamesmontemagno jamesmontemagno modified the milestones: 1.1.1, 1.2.0 Jun 18, 2019
Mrnikbobjeff pushed a commit to Mrnikbobjeff/Essentials that referenced this issue Aug 28, 2019
…arin#773)

* Implement Open File in Launcher.  Fixed xamarin#601 & xamarin#425

* Add title to open file request for android launcher

* Clean FileBase and AttachmentName. Added documentation.

* Fix encoding

* Remove namesapces that aren' t needed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request A request for a new feature. in-progress Actively being worked on.
Projects
None yet
Development

No branches or pull requests

7 participants