Custom URI Schemes for the Facebook Messenger

后端 未结 5 1598
野性不改
野性不改 2020-11-27 16:21

Given the recent \"encouragement\" by Facebook to migrate to a separate messenger app, and as a followup to the {very informative!} answer to the question on URL/URI schemes

5条回答
  •  [愿得一人]
    2020-11-27 16:42

    I know it is late but i hope it can help others

    For my case i wanted to open my page messenger bubble if installed of course

    So here what worked for me :

    messengerButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String messengerUrl ;
                    if (isMessengerAppInstalled()) {
                        Toast.makeText(ServiceClient.this, "messenger is installed , open app bubble", Toast.LENGTH_SHORT).show();
                        messengerUrl = "fb-messenger://user/475527699675914/";
                    } else {
                        Toast.makeText(ServiceClient.this, "messenger is not installed , open messenger in browser", Toast.LENGTH_SHORT).show();
                        messengerUrl = "https://www.messenger.com/t/475527699675914/";
                    }
                    Intent messengerIntent = new Intent(Intent.ACTION_VIEW);
                    messengerIntent.setData(Uri.parse(messengerUrl));
                    startActivity(messengerIntent);
    
    
                }
            });
    
    public boolean isMessengerAppInstalled() {
            try {
                getApplicationContext().getPackageManager().getApplicationInfo("com.facebook.orca", 0);
                return true;
            } catch (PackageManager.NameNotFoundException e) {
                return false;
            }
        }
    

提交回复
热议问题