how to open android application if installed and go to android market if not install

后端 未结 4 1805
滥情空心
滥情空心 2020-12-30 02:48

I would like to make android button and able to launch other application if already installed and go to android market if not yet installed.

How to do this?

相关标签:
4条回答
  • 2020-12-30 03:40

    use below code

    String packageName = "app_package_name";
    Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
    
    if(intent == null) {
       intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+packageName));
    }
      startActivity(intent);
    
    0 讨论(0)
  • 2020-12-30 03:41

    inside onclick

    @Override
    public void onClick(View view){
      try{
        startActivity(getPackageManager().getLaunchIntentForPackage("applicationId"));
      } catch (PackageManager.NameNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + "applicationId")));
     }
    }
    
    0 讨论(0)
  • 2020-12-30 03:47

    Try with this -

    Just create one Button in your layout. And, onClick of that button check below condition -

    Button calculateButton = (Button) findViewById(R.id.buttonCalculate);
        calculateButton.setOnClickListener(new View.OnClickListener() {
    
              public void onClick(View v) 
              {
                  if(check() == true)
                  {
                      PackageManager pack = this.getPackageManager();
                      Intent app = pack.getLaunchIntentForPackage(packagename);
                      startActivity(app);
                  }else
                  {
                      Intent marketIntent = new Intent(Intent.ACTION_VIEW);
                      marketIntent.setData(Uri.parse("market://details?id=packagename"));
                      startActivity(marketIntent);
                  }
             }
        });
    }
    
    public boolean check()
    {
        try{
            ApplicationInfo info = getPackageManager().getApplicationInfo("packagename", 0 );
            return true;
        } catch( PackageManager.NameNotFoundException e ){
            return false;
        }
    }
    
    0 讨论(0)
  • 2020-12-30 03:47

    Try to call the Application activity from your code using the, other application package name and activity name or by the Intent filters which is belongs to that other application you need to call...

        Intent newIntent;
        newIntent = new Intent("other application Package name","class name");
        startActivity(newIntent);
    

    Check whether it is launched or not.

    //If it is launched, don't do anything

    //If it isn't, then navigate the UI to Google Play Intent.

      Intent googlePlay = new Intent(Intent.ACTION_VIEW);
      googlePlay.setData(Uri.parse("market://details?id="+"other application package name"));
      startActivity(googlePlay);
    
    0 讨论(0)
提交回复
热议问题