Saturday, July 28, 2018

Adding Social Media Share Logic From Firebase in Android

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

}
});

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...