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.
Related
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
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.
Is It Possible To open 2 url At a time from android app without opening the layout.
I can open these two in two different activity or using two button in same activity.
Uri uri = Uri.parse("http://www.facebook.com");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
Uri uri = Uri.parse("http://www.gmail.com");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
Is it possible to open them from same activity directly as the application start??
AFAIK You can not open two links at the same time and view in activity.As you can have access to the single activity at a time in android, So browser is a kind of activity which you are requesting for opening url. You can not show two different links at a same time.
But yes its possible to open link directly at the start up of application.
I want to let the user to visit my website by click a button.
However, I want the app to open the google chrome or other external web browser to open the website instead of load the url with WebView.
How can I do that?
You can do it with an ACTION_VIEW Intent --
Uri myUri = Uri.parse("http://www.whereever.com/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(myUri);
startActivity(intent);
If you want to do it on a button click, you will need to put it in the onClick method of your onClickListener.
I have an app which wants to view an image in the gallery app.
I use this code to view it:
File cachedImage = cache.getFile(image.getImageUrl());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cachedImage), "image/*");
startActivity(intent);
This works except when I click the edit setting here:
and I get the no apps can perform this action message:
Is there some way to make this work? Do I need to pass additional extras? I know the Gmail app is able to view an image attachment in the gallery and the edit function works. This is on JellyBean.
Is there some way to make this work?
Install an app that can edit pictures. Your screenshots appear to be of the Gallery app, which is presumably trying to use ACTION_EDIT to start an activity to edit the picture, and there is no such activity available.