How do I programmatically launch a specific application?

后端 未结 10 673
余生分开走
余生分开走 2020-11-29 03:43

I want to launch a specif application.

I know how to do Intents but I want to avoid the selection menu if there are multiple apps that can handle the intent, I want

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 04:37

    I've resolved issue by

    String packageName = "Your package name";
    
    Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
    
    if(intent == null) {
        try {
            // if play store installed, open play store, else open browser 
             intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
        } catch (Exception e) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
        }
    } 
    startActivity(intent);
    

提交回复
热议问题