Android - Share on Facebook, Twitter, Mail, ecc

后端 未结 13 2539
眼角桃花
眼角桃花 2020-11-27 09:43

I need to develop an app that has the share function. I have to share on Facebook, twitter, email and maybe other services.

How can I do this? There a library on th

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 10:22

    This will help

    1- First Define This Constants

     public static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana";
        public static final String TWITTER_PACKAGE_NAME = "com.twitter.android";
        public static final String INSTAGRAM_PACKAGE_NAME = "com.instagram.android";
        public static final String PINTEREST_PACKAGE_NAME = "com.pinterest";
        public static final String WHATS_PACKAGE_NAME =  "com.whatsapp";
    

    2- Second Use This method

     public static void shareAppWithSocial(Context context, String application, String title, 
     String description) {
    
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setPackage(application);
    
            intent.putExtra(android.content.Intent.EXTRA_TITLE, title);
            intent.putExtra(Intent.EXTRA_TEXT, description);
            intent.setType("text/plain");
    
            try {
                // Start the specific social application
                context.startActivity(intent);
            } catch (android.content.ActivityNotFoundException ex) {
                // The application does not exist
                Toast.makeText(context, "app have not been installed.", Toast.LENGTH_SHORT).show();
            }
    
    
        }
    

提交回复
热议问题