12
votes

I am building an android instagram clone app with Firebase. I have enabled social media sharing buttons in my app to share the contents of a story via Facebook, email, WhatsApp, etc but don't know how to go about it.

Take a look at what I've tried:


    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"));

            }
        });

3

3 Answers

3
votes

Since your sharing the post content try changing your from:

intent.setType("*/*");

To:

intent.setType("text/plain");
0
votes

I assume you want to share Image and Text(description or some other details) both for that you can have a look at this question

If you want to add a link to your app, something like in apps like Reddit/Instagram have a look at this question

You can combine both to share the Image and Text (url + small description/username) to any app that accepts it like WhatsApp

Hope it helped!

0
votes

You should try

shareIntent.setType("text/plain"); 

instead of

shareIntent.setType("*/*");