2013年5月29日 星期三

How to check if the application is installed or not in android programmatically [duplicate]


22down voteaccepted
Try with this,
 public class Example extends Activity
    {
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            //Put the package name here...
            boolean installed  =   appInstalledOrNot("com.Ch.Example.pack");  
            if(installed)
            {
            //This intent will help you to launch if the package is already installed
            Intent LaunchIntent = getPackageManager()
                .getLaunchIntentForPackage("com.Ch.Example.pack");
        startActivity(LaunchIntent);


                      System.out.println("App already installed om your phone");


            }
            else
            {
                System.out.println("App is not installed om your phone");
            }
        }
        private boolean appInstalledOrNot(String uri)
        {
            PackageManager pm = getPackageManager();
            boolean app_installed = false;
            try
            {
                   pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                   app_installed = true;
            }
            catch (PackageManager.NameNotFoundException e)
            {
                   app_installed = false;
            }
            return app_installed ;
    }
    }
share|improve this answer

沒有留言:

張貼留言

Related Posts Plugin for WordPress, Blogger...