Open third-party application

I am developing an application that uses packagenames to run a third-party application. I did some research and found out that all applications can be launched with the intention of launching. Is there anyone who knows how to do this with the click of a button.

+1
source share
3 answers

You cannot "run applications". You can try to get the Launch Intent from a third-party application if you know the package_name:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.thirdparty.package");
startActivity( intent );
+6
source

For the answer above, if a third-party application is not installed on your emulator, you should also process it. Here is the complete code for this:

public void openThirdPartyApp() {   

        Intent intent = new Intent("com.thirdparty.package");
            intent.setPackage("com.thirdparty.package");

            try {
                ((Activity) context).startActivityForResult(intent, REQUEST_CODE);
            } catch (ActivityNotFoundException e) {
                downloadIt();
            }
        }

    private void downloadIt() {

    Uri uri = Uri.parse("market://search?q=pname:" + "com.thirdparty.package");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

                try {
                    context.startActivity(intent);
                } catch (ActivityNotFoundException e) {
    //creates a small window to notify there is no app available 
                }   

            }
        }

    }
+4
source

View.OnClickListener:

myButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = getPackageManager().getLaunchIntentForPackage(theOtherActivityPackage);
        startActivity( intent );
    }
});
+2
source

All Articles