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

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?

Regards, Virak


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));

Try with this -

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

Button calculateButton = (Button) findViewById(;
    calculateButton.setOnClickListener(new View.OnClickListener() {

          public void onClick(View v) 
              if(check() == true)
                  PackageManager pack = this.getPackageManager();
                  Intent app = pack.getLaunchIntentForPackage(packagename);
                  Intent marketIntent = new Intent(Intent.ACTION_VIEW);

public boolean check()
        ApplicationInfo info = getPackageManager().getApplicationInfo("packagename", 0 );
        return true;
    } catch( PackageManager.NameNotFoundException e ){
        return false;

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");

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"));

inside onclick

public void onClick(View view){
  } catch (PackageManager.NameNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("" + "applicationId")));

Need Your Help

java : accessing static variables inside static block

java static

Analyzing some weird scenarios in following static block :

CSS div element - how to show horizontal scroll bars only?

css html

I have a div container and have defined its style as follows: