首页 文章

在Android中从Firebase添加社交媒体共享逻辑

提问于
浏览
3

我正在使用Firebase构建一个android instagram克隆应用程序 . 我在我的应用程序中启用了社交媒体共享按钮,通过Facebook,电子邮件,WhatsApp等分享故事的内容,但不知道如何去做 .

看看我尝试过的东西:

public class InstacloneApp extends AppCompatActivity {

    private RelativeLayout relativeLayout;

    private ImageView postCoverImg, userPhotoUrl;
    private TextView post_Title, post_Descpn, post_Author, postDate;

    private Button commentsBtn;
    private FloatingActionButton shareFAB;

    private String post_details = null;
    private FirebaseAuth mAuth;
    private DatabaseReference postRef;

    private Context mCtx = this;
    private String uid_post = null;

    private ScrollView scrollView;
    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_insta_clone_app);

        relativeLayout = (RelativeLayout) findViewById(R.id.activity_blog_posts_view);
        scrollView = (ScrollView) findViewById(R.id.scrollView);
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        toolbar.setTitle("");
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        post_details = getIntent().getExtras().getString("post+key");

        postCoverImg = (ImageView) findViewById(R.id.post_Backdrop);
        post_Title = (TextView) findViewById(R.id.post_title);
        post_Descpn = (TextView) findViewById(R.id.post_description_long);
        post_Author = (TextView) findViewById(R.id.authorTV);
        userPhotoUrl = (ImageView) findViewById(R.id.author_photo);
        postDate = (TextView) findViewById(R.id.post_date);
        shareFAB = (FloatingActionButton) findViewById(R.id.shareFAB);
        commentsBtn = (Button) findViewById(R.id.commentsBtn);

        mAuth = FirebaseAuth.getInstance();

        postRef = FirebaseDatabase.getInstance().getReference().child("Blog").child("All_Posts");
        postRef.keepSynced(true);

        postRef.child(post_details.toString()).addValueEventListener(new ValueEventListener() {  // this is to retrieve and view the blog post data
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                String title_post = (String) dataSnapshot.child("postTitle").getValue();
                String desc_post = (String) dataSnapshot.child("full_postDesc").getValue();
                String backdrop_post = (String) dataSnapshot.child("postImage").getValue();
                String date_post = (String) dataSnapshot.child("postDate").getValue();

                uid_post =  (String) dataSnapshot.child("uid").getValue();  

                post_Title.setText(title_post);
                post_Descpn.setText(desc_post);
                postDate.setText(date_post);
                Glide.with(mCtx).load(backdrop_post).into(postCoverImg);

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

        shareFAB.setOnClickListener(new View.OnClickListener() {  // my implemented share action
            @Override
            public void onClick(View view) {

                String content = post_details;

                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                shareIntent.setType("*/*");
                shareIntent.putExtra(Intent.EXTRA_TEXT,content);
                startActivity(Intent.createChooser(shareIntent,"Share With"));

            }
        });

1 回答

  • 1

    由于您分享了帖子内容,请尝试更改以下内容:

    intent.setType("*/*");
    

    至:

    intent.setType("text/plain");
    

相关问题