App

PowenKo > Android > APP > get version name and version code

March 26, 2012   ·   0 Comments

Screen Shot 2012-03-25 at 7.35.08 PM


sample code: Tutorial_apk_check_latest_app_marketActivity

package com.powenko;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;

public class Tutorial_apk_check_latest_app_marketActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Fun_APP_version();
    }
    private void Fun_APP_version(){ //check_new_version(){

    	String strVersion;
    	  
    	   PackageInfo packageInfo;
    	   try {
    	    packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    	    strVersion = "Version Name: " + packageInfo.versionName +"\n"
    	       + "Version Code: " + String.valueOf(packageInfo.versionCode);
    	   } catch (NameNotFoundException e) {
    	    // TODO Auto-generated catch block
    	    e.printStackTrace();
    	    strVersion = "Cannot load Version!";
    	   } 
    	  
    	   new AlertDialog.Builder(Tutorial_apk_check_latest_app_marketActivity.this)
    	   .setTitle("About Me!").setMessage(strVersion)
    	   .setPositiveButton("OK",
    	    new DialogInterface.OnClickListener() {
    	     public void onClick(DialogInterface dialog, int which) {}
    	     }).show();
    	  
    	   
    }
    private String SendNetworkUpdateAppRequest(){
    	
    	return "";
    }
    private boolean Fun_APP_check_new_version(){
    	
    	
    	String response = SendNetworkUpdateAppRequest(); // Your code to do the network request
        // should send the current version
        // to server
    	if(response == "YES"){ // Start Intent to download the app user has to manually install it by clicking on the notification
    			startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("URL TO LATEST APK")));
    	return true;
        
    	}
    return false;
    
    }

}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon