CodeChrist - This is a personal blog which I write to help follow coders

If you like it, feel free to comment and appreciate the good work


Following are the some features of CodeChrist

  • Easy to navigate and use.
  • You can subscibe for emails
  • CodeChrist is beautiful on every screen size (try resizing your browser!)
by

How to check programmatically if an application is installed or not in Android?

If the application is already installed in the device the application is open automatically.
Otherwise install the particular application.

    public class Example extends Activity {
  1.     @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 is already installed on your phone");         
            } else {
                System.out.println("App is not currently installed on your phone");
            }
        }
    
        private boolean appInstalledOrNot(String uri) {
            PackageManager pm = getPackageManager();
            boolean app_installed;
            try {
                pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                app_installed = true;
            }
            catch (PackageManager.NameNotFoundException e) {
                app_installed = false;
            }
            return app_installed;
        }
    }

0 comments:

Post a Comment