0

I want when my app is opened check a file in server for example: mysite/last.txt

and in this file I put last app version like: 3.3

I want every time user opens the my app, first check this file and check if the app version is lower than the version that I put in text file in server, show a dialog or toast message to user for new version if app for example: "a new version is available"

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mojtaba GS3
  • 51
  • 1
  • 12

4 Answers4

0

perform the check inside the onCreate() method of your main activity

Basil
  • 845
  • 9
  • 24
0

You could download the files content using a normal Http connection: How do I use the Simple HTTP client in Android?

But why should you want to do this? The play store keeps track of the versions and will show a message if theres an update for your app!

Community
  • 1
  • 1
danijoo
  • 2,823
  • 4
  • 23
  • 43
0

onCreate() of ur start activity simply write a asyncTask and in doInBackground method of asyncTask check for ur version if availbale in postexecute of AsyncTask show a toast or notification which ever u want

private class CheckVersion extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(String... params) {


//here ur service goes to check the version of app

    }      

    @Override
    protected void onPostExecute(String result) {               
        // show notification 
    }
}

In onCreate of ur start activity u can call CheckVersion.execute();

KOTIOS
  • 11,177
  • 3
  • 39
  • 66
0
import android.os.Bundle;

public class SomeActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        new AsyncClass().execute("someurl");
//above line will call the doInBackground()
    }   

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }


private class AsyncClass extends AsyncTask<String,Void,String>{

    @Override
    protected String doInBackground(String url) {


        HttpClient client =new DefaultHttpClient();
        HttpGet getreq =new HttpGet(url);

        HttpResponse resp=client.execute(getreq);

        return parserResponseFromServer(resp);
        //above line will pass the control to onPostExecute()
    }

    private String parseResponseFromServer(HttpResponse response) throws IllegalStateException, IOException {
        // TODO Auto-generated method stub
        BufferedReader reader=new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line_read=null;
        StringBuilder builder=new StringBuilder();
        while((line_read=reader.readLine())!=null){
            builder.append(line_read);
        }
        return builder.toString();
    }


    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub

        //HERE the result will be the response from the server.
        `

    }
}

}
cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
  • put it on server......where you want to read/parse the file..i guess proper way should be you should call the url with the current version and compare it on server by reading.the file as given above..ad return a true or false from your server and depending on that do watever yu feel like . – cafebabe1991 Aug 15 '13 at 17:16
  • //// put the asynctask code in an inner class insode your activity //and the file reading code goes at your server and what your server responds with will be accessible in doInBackground function ....builder.toString will show the response from server – cafebabe1991 Aug 15 '13 at 17:28
  • can u attach the java activiy file for me that do this? – Mojtaba GS3 Aug 16 '13 at 16:50
  • i have edited the code above check it.If that helps you dnt' forget to like it :-) – cafebabe1991 Aug 17 '13 at 10:15