-3

I have two buttons on splash screen and I want check if app install or not and give result if app install the button start is work and users can click to go main activity and the other button is disabled click and if the app doesn't install the button start disable and button install and download is working.. how do this?

  final Button down_install = (Button) findViewById(R.id.bt_down_install);
        final Button start = (Button) findViewById(R.id.bt_start);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    boolean isAppInstalled = appInstalledOrNot("com.facebook.android");
                    if (isAppInstalled) {
                        Intent Start_screen = new Intent(SplashScreen.this, MainActivity.class);
                        startActivity(Start_screen);

                    } else {

                        start.setEnabled(false);


                }

            }

            private boolean appInstalledOrNot(String uri) {
                PackageManager pm = getPackageManager();
                try {
                    pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                    return true;
                } catch (PackageManager.NameNotFoundException e) {
                }

                return false;


            }
        });
h.vc32
  • 1
  • 4
    Possible duplicate of [How to check programmatically if an application is installed or not in Android?](https://stackoverflow.com/questions/11392183/how-to-check-programmatically-if-an-application-is-installed-or-not-in-android) – ADM Dec 04 '17 at 07:17

2 Answers2

0
 if (isAppInstalled) {
    Intent Start_screen = new Intent(SplashScreen.this, MainActivity.class);
    startActivity(Start_screen);
 } else {
    //start.setEnabled(false);
    start.setOnClickListener(null);
 }
Jackey kabra
  • 199
  • 1
  • 9
0

try { //use packagename of app which you want to check getPackageManager().getPackageInfo("com.example.helloworld", PackageManager.GET_ACTIVITIES);

    } catch (PackageManager.NameNotFoundException e) {
    }