I tried to open the video from url with Intent.ACTION_VIEW, and it was successful.
But, the problem is, after the browser appeared for a second and it's automatically minimize and the front is the activity on the apps.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("the url of the video with format .m3u8");
intent.setData(data);
startActivity(intent);
I'm expecting exactly the same way when i put the URL into the browser manually, but without minimize the browser when it has already been launched.
Need some flags? grateful for any response and suggestions.
I bet that the browser is just quitting as a result of an inability to display the content. If you plug in the video url to the browser manually, does it work? What is the filetype of the content you are trying to display?
Have you tried explicitly setting data type by using setDataAndType(Uri data, String type) where mime type is "audio/x-mpegurl" (the full mime type is "audio/x-mpegurl; charset=UTF-8"). You might have some switch statement to check URL user has clicked to force type in case link points to ".m3u8".
Related
I want to open a data: url containing a pdf in an activity in my android application. I have something like the following code:
String url = "data:application/pdf;base64,JVBERi0xLjIgDQol4uPP0w0KIA..."; // shortened for brevity
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
I am seeing an error:
error opening uri: No Activity found to handle Intent {
act=android.intent.action.VIEW dat=data:application/pdf... (followed
by the rest of the data url).
How can I resolve this?
Since approximately zero apps in existence will support that scheme, you will need to decode the PDF yourself, write it to a file, and then open the PDF viewer on the file.
You need to have an app that can handle opening pdf documents. If you still wish to do this catch an ActivityNotFoundException and tell the user to download one.
what is the correct way how I should form the intent to show content from my app in 3rd party viewers? I need to show images in gallery (or any other image viewer), pdfs in some pdf reader,..
Data gets server through a content provider which implements the openFile() method and returns a output pipe..
ParcelFileDescriptor[] pipe=ParcelFileDescriptor.createPipe();
...
ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
PipeThread pipeThread = new PipeThread(fileContents, stream);
pipeThread.start();
return pipe[0];
For images I use this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
I'm creating then a chooser for this intent as usual that's not the issue..
My problem is that although I see for example the Photos app in the chooser, I just cannot open the file in it..It just only opens the gallery with my images.
It's working when I use the action send, apps like gmail, drive, dropbox,..all of them are able to correctly read the image from the provider.
Also Skitch seems to be the only one app which I have tested it on that is able to open the image also using the Intent.ACTION_VIEW action..
Please don't tell me I should just send the URI, I really need to provide the file as a stream, or somehow as a serie of bytes (IPC limitations would be probably against this). I can't save the file to a public directory.
So the issue was that have been setting Intent type and data in two separate method calls..
What I didn't know is that Intent.setType() clears its data and Intent.setData() clears its type..
When I set both data and type through the Intent.setDataAndType() method call, it works even for URI pointing to a stream.
Unfortunately the final implementation is still not working flawlessly everywhere.
It works in default android gallery app, in G+ Photos app, in QuickPic, in Sony gallery app, but it does not work in default HTC gallery neither in default Samsung gallery.
Its just a pity, that its actually not that much dependent on my implementation as on how is it implemented in the 3rd party viewer app.
As the docs say: "ACTION_GET_CONTENT could allow the user to browse over the web and download the desired data".
And that's what I need, from Google Images. Although, if I use this intent's type the app crashes (I suppose it only expects ACTION_VIEW to open the browser):
Intent intent = new Intent();
intent.setData(Uri.parse(url));
intent.putExtra("return-data", true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICK_IMAGE);
It needs to (edited to clarify what I need):
Estabilish the connection to the web browser
The URL to Google Images
Retrieve the image's URL after the user has chosen one (it needs to close the browser, the ACTION_VIEW just keeps on going until the user decides to close it and does not retrieve any information).
As far the URL I have is this one, but it needs something else because it is going to a default search, not for images:
String url = "http://images.google.com/search?q=" + imagename;
I appreciate any help.
Try using the following url. It works fine for me in my app:
"http://images.google.com/search?num=10&hl=en&site=&tbm=isch&source=hp&biw=980&bih=710&q=" + YourQueryString
You need the tbm query parameter set to the value isch for image search. So the minimal URL would look like:
"http://google.com/search?tbm=isch&q=" + queryString
I want open the android browser, and set the html data on it. I do not want to use webview control. How can I do that?
Try the following:
String URL= [url];
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(intent);
You can save the html file locally on the SD and give the url to it.
Good Luck
Not specific to android, but to generic morden browsers:
You can make entire document into a long string of URI, and then locate that to show the original document. See http://en.wikipedia.org/wiki/Data_URI_scheme.
Someone provides a handy web-based tool to convert any document into Data URI string:
http://www.dopiaza.org/tools/datauri/
The size limit varies among the specific web browsers.
Hi
I want to write an app to call default browser and redirect to a designated url.
Any suggestion to 1)call the default browser, 2)redirect to a designated url.
Thanks
you just want to launch an ACTION_VIEW intent with the Uri of the webpage as your data element :
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("http://www.bbc.co.uk"));
startActivity(httpIntent);
To open the default browser use an Intent with the action VIEW. To tell the browser which page to load us the data-part of the Intent.
Example:
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com"));
startActivity(browse);
Since this is a basic task in Android you might want to read some basics about Intents in Android.