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");
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?
Is it possible to open a google map url with latlng values into an external web browser?
Currently I have used simple Intent but it open into Google map, Please help me if it possible.
You can use this:
String url = "http://maps.google.com/maps?q=loc:23.070791,72.520004";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
startActivity(intent);
I hope this will helpful
I am developing an app that takes the input url from user (www.xyz.com) and then I am writing this code to hit the link in the browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(Url));
startActivity(browserIntent);
I saw that the http/https are not added automatically then I added it myself by doing Uri.parse("http://"+"Url). but is there any way to do this task automatically? Can anyone suggest a better solution for it because when I hit the links in my solution I am not sure the link I am hitting is https or http.
Uri.parse() will only convert the given String to uri. It doesn't know what type of url/uri is it (http or https). So yes, you have to add it yourself
Although you can set a static text in your EditText so that when user enters the text/url, the http or httpsis static and cannot be edited.
editText.setText("http://");
Selection.setSelection(editText.getText(), editText.getText().length());
Actually you can check first if the url that user enter starts with http/https or not, if yes, you can ignore, and if no, you can add "http://" by the code
String textFromUser = editText.getText().toString();
textFromUser = textFromUser.startsWith("http://") || textFromUser.startsWith("https://") ? textFromUser : "http://" + textFromUser;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(textFromUser));
startActivity(browserIntent);
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 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);