Question

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.

Était-ce utile?

La solution 2

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.

Autres conseils

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>

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top