How do I programmatically launch a specific application?

后端 未结 10 672
余生分开走
余生分开走 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:40

    I use:

      try {
           Intent intent = new Intent();    
           intent.setClassName("package.name", "");
           startActivity(intent);
        } catch (NameNotFoundException e) {
           Log.e(TAG, e.getMessage());
        }
    

    But like Cami suggested this will work too:

    try {
        Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.twidroid.SendTweet");
        ctx.startActivity(i);
    } catch (NameNotFoundException e) {
         Log.e(TAG, e.getMessage());
    }
    

提交回复
热议问题