0

My application has a feature to view the file which is stored on server.

Currently, I am using the following code to view the file stored on server:

String url = "http://www.google.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

But this is firstly download the file from the server. and then open the file by using respective application.

But is it possible to view file directly with out downloading?

Please help me. Thanks in advance.

Manali Sheth
  • 379
  • 2
  • 5
  • 17
  • 2
    Viewing it without downloading is impossible. You could only download parts of it, or download a preview or something, but you have to download somethind. You don't have to store it, though. – tilpner Apr 23 '14 at 11:39
  • Hi...Thanks for the Response...:) Yes...I do not want to store file on my device then how can I view it...? – Manali Sheth Apr 23 '14 at 11:40
  • Without downloading I think its not possible manali, I think there should be some online tools to do it, so just search for it, if any third party library should provide this kind of feature. – Pratik Dasa Apr 23 '14 at 11:43

4 Answers4

1

try this,

try {  
        URL url = new URL("your url");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String string;
        while ((str = in.readLine()) != null) {

        }
        in.close();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
</code>
Nikesh Pathak
  • 450
  • 2
  • 7
  • 18
0

But is it possible to view file directly with out downloading?

NO, as far as I know. Whenever you want to view the content on the server, those are first downloaded to client. How much data is downloaded at a time, depends on the implementation.

Ritesh Gune
  • 16,629
  • 6
  • 44
  • 72
0

As I said in my comment, viewing a file requires downloading it.
What you might mean, is that you don't want to store it.

The problem is that the Android intent system doesn't offer this degree of flexibility, which is usually a good thing. You tell it to view a file, and it does that with whatever app it can. And there's no problem with storing it, you have to store it. The problem is where you store it. To view it, you have to at least store it in memory, storing it as an Android managed temporary file could also fulfill your need, and what's wrong with just storing it somewhere else and deleting it afterwards?

If you really need to store it to a custom place you'll have to leave the intent system and do the downloading yourself.

tilpner
  • 4,351
  • 2
  • 22
  • 45
  • Hello...Thanks for the reply. Exactly...I do not want to store a file on an android device because of some security reasons. Can you please give me code for it? – Manali Sheth Apr 24 '14 at 09:47
  • Really, there are [numerous](http://stackoverflow.com/questions/16723714/how-to-read-and-use-the-content-of-a-website-in-android-app) [examples](http://stackoverflow.com/questions/17271147/android-get-content-from-url) [of](http://www.coderzheaven.com/2011/07/17/how-to-read-webpage-contents-as-a-string-in-android/) [this](http://argillander.wordpress.com/2011/11/23/get-web-page-source-code-in-android/) on the internet. – tilpner Apr 24 '14 at 11:56
  • Hi..Thanks for the response. I got my solution... :) – Manali Sheth Apr 25 '14 at 13:30
0

With an intent for "http://www.google.com"; you are not downloading any file. You are not specifying a file either. The default application will contact "http://www.google.com"; and receive some html source. That has nothing to do with a file.

greenapps
  • 11,154
  • 2
  • 16
  • 19