Android download file through browser - android

var uri = Droid.Net.Uri.Parse(url);
var intent = new Intent(Intent.ActionView, uri);
intent.SetFlags(ActivityFlags.ClearTop);
StartActivity(intent);
(Code is xamarin)
This code will open a page that is actually download of a PDF. After the file is downloaded, chrome will close the tab and show the last tab the user was looking at and pressing back will just continue to move back in chrome, not going back to the app.
Can it be done that when the file is downloaded user is returned to the app instead of being in chrome (or other browser)?

If you use ActivityFlags.NewTask you will get the desired effect. Only issue with downloading file is that the tab that downloads a file will close and you will get the tab that was opened before it, but if you press back button it will go back to your app.

Related

Android / Xamarin, Open file with intent and close app after back button pressed

I have a problem with a feature of my application.
I need to open external files to display them like .jpeg or .xls for example. For that I use Intents to open them with the default system application and it works fine.
But in a case where we will first open a document, for example a photo. this will display in the default app and then I go back and forth in my app. Everything is OK
But then I'm going to open another standard .xls document, it'll open the document in the appropriate application and going back will show the opened image first and not my application again.
I don't understand why it happens like this.
What I would like is that when we do previous in a file viewer app, the app quits and doesn't stay in the ActivityManager.
Is it possible ?
I have already tried some intent flags but without success.
My code here :
Android.Net.Uri fileUri = FileProvider.GetUriForFile(Android.App.Application.Context, "com.app.fileprovider"
, file);
Intent intent = new Intent(Intent.ActionView);
intent.SetData(fileUri);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
intent.AddFlags(ActivityFlags.NewTask);
intent.AddFlags(ActivityFlags.NoHistory);
Android.App.Application.Context.StartActivity(intent);
return true;
Thanks a lot for the help
Max B
SO !
My bad, It was not a real problem.
It was a design error.
Indeed during my call of my function to call the intention I linked my opening event without then unbinding it. So that with each call I recalled X times my file opening function without ever destroying my variable or my variable instance.
The Intent Works Well
Thanks for the comments

Intent.ACTION_GET_CONTENT opens different folder in Gallery on different flavours of the app

I have following piece of code,
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICK);
When i try to choose image, it opens recents in one flavour of app and in another, it opens screenshots, is there a way I can force to open same directory/folder inside gallery app so behaviour is synced on both flavours.
It seems to start in the last folder a photo was selected from. I.e. if I open app A and set an image from folder “Foo”, it will open in “Foo” the next time as well. The setting is separate for the app B. If I set an image from folder “Bar” in the app B it will open in “Bar” the next time in the app B, but still “Foo” for the app A.

How to open Image from URI in Android 4.4

I have opened image from Uri it work good for me at 4.3 version But in 4.4 version it show a back button on top of image and when i clicked on that back button it take me gallery so in this case i am going out of my app so how can prevent this please help me..below is my code.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File photo_file = new File(path);
intent.setDataAndType(Uri.fromFile(photo_file), "image/*");
startActivity(intent);
That isn't a back button - it is an Up button, providing ancestral navigation within the Gallery/Photo viewing app. You'll note the back button still works as you expect, providing temporal navigation (i.e., back from where you came from).
There's no way to customize the view of another activity you do not own, although you can certainly go about and create a photo viewer of yourself where you get full control of the UI.

Getting data from intent

I am little confused about getting data from intent of an activity, here is what I am trying to do.
I am opening my first activity
I press home button and my activity(application) goes in background
I go to download folder and select one doc file it gives me Open with feature with my application in list.
I select my application.
Now instead of getting resume it calls create method of activity(I think its ok because second instance of my app(activity is created))
Here I try to get data from intent using intent = activity.getIntent();
But I dont get anything(getting null expecting path of this doc)
If I first open my app with Open with feature(No background activity right now) I get file path successfully but when I pres home button and my app goes background again and if I press my app from application list again intent has same data(expecting null in this case.)
What I am trying to achieve:-
I am simply trying that if user is coming from application list intent data should be null and if he is coming from Open with function then he intent data should be path of file.
One more thing I am trying this behaviour in Appcelerator Titanium but as this is native behaviour(handling life cycle of activity and I can do this in titanium) but having no luck.
Thanks.
I some what manage this by giving my activity as 'singleInstance' in manfiest file. So now I can be sure that at a time same instance is running.
Now for handling intent data I am registering onNewInstance method. By using this intent data is get affected everytime when I comes from background or when when I select any file to open with my application.
Thanks.

Getting Webview Activity to Disappear with PDF Link Action_view

I'm downloading a PDF in my application using:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("*url for your pdf*"));
startActivity(browserIntent);
This opens an activity that looks like a webview and begins the pdf download in the drop down menu. I'd like to keep the drop down download notification but is there a way to close the webview activity once the download starts? Or even better keep the webview from popping up in the first place?
Instead of calling a Uri intent, you could download the file to the sd card if it is not already there (using notification for progress), then call action_view on the file. That should open it directly in the preferred PDF viewer.

Categories

Resources