Android share intent for Facebook

前端 未结 4 1659
清歌不尽
清歌不尽 2020-12-06 08:37

I have some problem with below code. This code is working for email, message, Twitter (for sending the text) but not for Facebook. Why?

Intent i=new Intent(a         


        
4条回答
  •  庸人自扰
    2020-12-06 09:17

    this is not working for facebook because Facebook can share only a link via ACTION_SEND. if U want to send Text As well as link.

    Firstly you have to get the list of installed application that support ACTION_SEND then buil a dialog

      Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        List activities = getPackageManager().queryIntentActivities(sharingIntent,0);
    

    after the activities now build a dialog to show activities .then get the intent for facebook and share it with facebook api all other to be handled by itself but please pass the class name for other activities.

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
                    sharingIntent.setClassName(,);
                    sharingIntent.setType("text/plain");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"hello");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "facebook"); 
    

提交回复
热议问题