When Required app Installed then Execute function | Android Studio

You want to make some app for required app installed then run, So add given code on your project and make this type of Android app.

How to Do

  • Open MainActivity.java then paste or add given code.
   new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            String url = "http://thekroyaard.com/age-calculator";
            Intent homeIntent = new Intent(Intent.ACTION_VIEW);
            homeIntent.setData(Uri.parse(url));
            homeIntent.setPackage("com.android.chrome");
            try {
                startActivity(homeIntent);
                finish();
                overridePendingTransition(0,0);
            }catch (ActivityNotFoundException activityNotFound) {
                makeText(MainActivity.this, "Install Google Chrome first", LENGTH_SHORT).show();
            }
        }
    } , SPLASH_TIME_OUT);
}

See full code with example

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                String url = "http://thekroyaard.com/age-calculator";
                Intent homeIntent = new Intent(Intent.ACTION_VIEW);
                homeIntent.setData(Uri.parse(url));
                homeIntent.setPackage("com.android.chrome");
                try {
                    startActivity(homeIntent);
                    finish();
                    overridePendingTransition(0,0);
                }catch (ActivityNotFoundException activityNotFound) {
                    makeText(MainActivity.this, "Install Google Chrome first", LENGTH_SHORT).show();
                }
            }
        } , SPLASH_TIME_OUT);
    }

}