Determining if an Activity exists on the current device?

前端 未结 5 1738
攒了一身酷
攒了一身酷 2020-11-29 06:28

Is there a way to check and see if an Activity exists on your device? If I have a youtube video link I want to specify it open in the YouTube PlayerActivity. However, I don\

5条回答
  •  星月不相逢
    2020-11-29 07:03

    I ended up doing:

            Intent intent = new Intent();
            intent.setClassName( "com.google.android.gsf", "com.google.android.gsf.login.AccountIntroActivity" );
    
            if(getContext().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                getContext().startActivity( intent );
            } else {
                getContext().startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
    

    This ensures that the google-specific Add Account intent exists, and if not, falls back on the general more general ACTION_ADD_ACCOUNTS.

提交回复
热议问题