I try to download a file through the browser. it's working perfectly if a have that :
String pdfUrl = "www.myLink.com/document/test.pdf";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdfUrl));
startActivity(intent);
However if the link is :
String pdfUrl = "www.myLink.com/document/test/";
It's very odd because it works on my browser "Chrome". I can download the 2 files....
Using the URL without the full file name will not work, because the Intent system does not know the type of the resource behind the URI - it will probably launch a browser pointed to that address instead of a PDF viewer. What you could do, however, is explicitly specify the content type behind your URL by using intent.setDataAndType() instead of intent.setData(), like this:
String pdfUrl = "www.myLink.com/document/test/";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(pdfUrl), "application/pdf");
startActivity(intent);
Related
I am using an intent to open up a specific string literal(the website address) in an Android device's browser.
If I go with
String myIntentString = "url:www.google.com"
Uri myInputUri = Uri.parse(myIntentString);
Intent intent = new Intent(Intent.ACTION_VIEW, myInputUri);
startActivity(intent);
Then the app crashes.
However, if I change my string to "http://www.google.com" (the correct format), then it obviously works.
Yes, this is a school assignment and it is specified that the string MUST be "url:www.google.com"
If it helps, this is the first assignment where we need to turn in the Android Manifest file. Does this mean it has to do with that?
What am I missing?
I want to pass the URL of a file located in FTP using intent from my android application to open it in google chrome. I am trying to pass it to google chrome application browser but it does not include a colon after the keyword ftp.
I am passing
"http://ftp://demo.wftpserver.com/download/manual_en.pdf/"
and it displays the following link in the URL box
"http://ftp//demo.wftpserver.com/download/manual_en.pdf/"
It is missing a colon after ftp and I want to pass that colon also in the URL.
The code I used is
String url = "http://ftp://demo.ftpserver.com/download/manual_en.pdf";
String uri = "googlechrome://navigate?url=" + url;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(uri));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setPackage("com.android.chrome");
Any help would be appreciated.
Just use the correct link:
String url = "ftp://demo.ftpserver.com/download/manual_en.pdf";
Here is the way I would do this:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("ftp://ftp.hosteurope.de/"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setPackage("com.android.chrome");
I have an app that among other things fires up a pdf reader to allow the user to view a document selected by the app. It works on my phone but not Samsung tablet. The intent seems to work fine and the selection of reader apps comes up but when the reader is selected, a short time later the error message” Can’t open file “ is shown.
The same app can also fire up browser and text applications to show other files and this works fine on the tablet. So my file references are all OK. External storage for WRITE in the manifest is set OK.
When I select the document on the tablet (not thru my app) it opens OK. I have selected the pdf part of the main app and extracted it into a simple pdf reading only app and still the same problem.
It seems to be specific to the tablet – can anybody help me?
Intent i = new Intent(Intent.ACTION_VIEW);
File file1 = new File(Environment.getExternalStorageDirectory() + "/Documents/A.pdf");
Uri ur=Uri.fromFile(file1);
i.setType("application/pdf");
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i) ;
Instead of this code
Intent i = new Intent(Intent.ACTION_VIEW);
File file1 = new File(Environment.getExternalStorageDirectory() + "/Documents/A.pdf");
Uri ur=Uri.fromFile(file1);
i.setType("application/pdf");
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i) ;
Use this way
File pdfFile = new File(Environment.getExternalStorageDirectory(),"namePdfFile.pdf");//File path
if (pdfFile.exists()) //Checking for the file is exist or not
{
Uri path = Uri.fromFile(pdfFile);
Intent objIntent = new Intent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);//Staring the pdf viewer
} else {
Toast.makeText(getActivity(), "The file not exists! ", Toast.LENGTH_SHORT).show();
}
To Read PDF in Browser Use below code :
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
Thanks to all for help. Actually I was just confused by the mime types. Read up on this and all is well. App working perfectly along the lines posted by Ironman
How do i use intent in android widget to open images in browser.
If the image is on the internet it would be as simple as this:
String url = "http://www.picturesnew.com/media/images/image-background.jpg";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
However if the image is inside of your assets you can't open it in the browser. That's because the browser accepts URI data that starts with http. Furthermore the browser is a separate app and one app can't use other apps assets.
You could dipslay the image through the use of a WebView though.
To open a website from your widget:
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.fakesite.com\articles"));
startActivity(intent);
I used to have this problem but I found a solution, so just decided to post it here just in case someone else needs it.
How to launch the native installer app to install an apk?
Many posts have the solution as below:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive");
context.startActivity(intent);
This is fine except a tiny but crutial detail:
the "path" string must start with file:// otherwise you'll get an exception such as
Unable to find an activity to handle the intent .....
So make sure the path starts with file://
Cheers.
Actually, instead of using the parse(...) method, you can simply use the fromFile(...) method of the Uri class (the Uri will automatically have the form "file://").
Thus:
final File file = new File(path);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);