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?
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;
}
}