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"));
}
});
Since your sharing the post content try changing your
from:
intent.setType("*/*");
To:
intent.setType("text/plain");
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!
You should try
shareIntent.setType("text/plain");
instead of
shareIntent.setType("*/*");
Related
I want to save data of authenticated users in Firebase, there are two ways to authenticate data in my app after which the user is taken to the MainActivity.Java. I would like to see if the user is using the application for the first time if so add the details to the user tree in Firebase RealtimeDatabase.
As of now after adding the code in OnCreate below the comment of adding the user, the app does not crash or give any errors, but it also does not hit the Firebase DB and update it.
Here is my code of the OnCreate section of the MainActivity.Java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Carousel
customCarouselView = findViewById(R.id.customCarouselView);
customCarouselView.setPageCount(sampleImages.length);
customCarouselView.setSlideInterval(4000);
customCarouselView.setImageListener(imageListener);
customCarouselView.setImageClickListener(new ImageClickListener() {
#Override
public void onClick(int position) {
// Toast.makeText(MainActivity.this, "Clicked item: " + position, Toast.LENGTH_SHORT).show();
redirectToHotDeals();
}
});
// -- Carousel
FirebaseAuth.getInstance().getCurrentUser();
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
// User is signed in.
String name = FirebaseAuth.getInstance().getCurrentUser().getDisplayName();
String email = FirebaseAuth.getInstance().getCurrentUser().getEmail();
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
NavigationView navigationView = findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
TextView navUsername = headerView.findViewById(R.id.emailText);
TextView navUID = headerView.findViewById(R.id.uid);
navUID.setText("ID: " + uid.substring(0, 10));
navUsername.setText(email);
} else {
// No user is signed in.
redirectToLogin();
}
// Action Bar
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Coupons List");
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
// Set Layout
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// Send Query to Firebase Db
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference("Data");
// Add User to DB or Update it
String name = FirebaseAuth.getInstance().getCurrentUser().getDisplayName();
String email = FirebaseAuth.getInstance().getCurrentUser().getEmail();
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
FirebaseUser fUser = FirebaseAuth.getInstance().getCurrentUser();
User user = new User(name, email);
mRef.child("User").child(fUser.getUid()).setValue(user);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Here is the image of the Firebase Database: I would like if the first child has the UID followed by the email and contact as its child.
Here is my User.Java:
public class User {
public String name, email, phone;
public User(String name, String email){
}
public User(String name, String email, String phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
}
You can use this piece of code to update values in your database:
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(),null);
mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Log.d("Tag","SignInWithCredential: success");
FirebaseUser fUser = mAuth.getCurrentUser();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
assert fUser != null;
User user = new User(fUser.getDisplayName(),fUser.getUid());
ref.child("users").child(fUser.getUid()).setValue(user);
}
else{
Log.w("TAG","SignInWithCredential: failure", task.getException());
Toast.makeText(MainActivity.this,"Authentication failed", Toast.LENGTH_SHORT).show();
}
}
});
Duplicate declaration for the NavigationView first. Define it as follows inside your onCreate():
navigationView = findViewById(R.id.nav_view);
And then;
NavigationView navigationView;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
About the Firebase data set, User node doesn't seem to be child of Data which you declared it like this:
mRef = mFirebaseDatabase.getReference("Data");
mRef.child("User").child(fUser.getUid()).setValue(user);
Instead, try this:
mRef = mFirebaseDatabase.getReference("User");
mRef.child("UID").setValue(user);
Note that we need to be sure that User node is the reference in here. It seems like there is another root reference which we need to check the whole structure but I've just give you the path of how to get and set the data.
However, as documentation said, you'll need to be authenticated-Logged-in to be able to use Firebase database update-remove or etc. Otherwise, you should change your rules to open for everyone can do edits or etc.
When the "Add Item to the menu" button is clicked it will show "item added" which means it should be added to my firebase database, but when I check it nothing is showing meaning it was not stored. :(
Here are my codes
public class addItem extends AppCompatActivity{
private Button btnAdd;
private EditText name,desc,price;
private StorageReference storageReference = null;
private DatabaseReference mRef;
private FirebaseDatabase firebaseDatabase;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_item);
name = (EditText) findViewById(R.id.txtName);
desc = (EditText) findViewById(R.id.txtDescription);
price = (EditText) findViewById(R.id.txtPrice);
storageReference = FirebaseStorage.getInstance().getReference();
mRef = FirebaseDatabase.getInstance().getReference("Item");
}
public void addItemToMenu(View v)
{
final String name_text = name.getText().toString().trim();
final String desc_text = desc.getText().toString().trim();
final String price_text = price.getText().toString().trim();
if (!TextUtils.isEmpty(name_text) && !TextUtils.isEmpty(desc_text) && !TextUtils.isEmpty(price_text))
{
Toast.makeText(addItem.this, "Item Added", Toast.LENGTH_SHORT).show();
final DatabaseReference newPost = mRef.push();
newPost.child("name").setValue(name_text);
newPost.child("desc").setValue(desc_text);
newPost.child("price").setValue(price_text);
}
check the rules for firebase in your firebase console and change rules according to your scenario..
Change your database rules to:
{
"rules": {
".read": true,
".write": true
}
}
I know this questions already has been asked by some peoples but Still I am getting issue fro last 1 day. I have chat application and My emoji is sent successfully and displaying perfect in Website but In TextView its returning strange characters. I am using this Library for Emoji in TextView
This is Response from Web
data
:
"{"type":"text","message":"\ud83d\ude29","to":"264","from":"175","group_id":"0","groupFlag":0}"
but My TextView showing this Value
ðÿ˜ðÿ˜¡ðÿ˜¡ðÿ˜¡
**My ScreenShot is Here **
Please guide me How can I show Emoji in TextView. ? My complete code is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.root_view);
emojiButton = (ImageView) findViewById(R.id.emoji_btn);
submitButton = (ImageView) findViewById(R.id.submit_btn);
emojiconEditText = (EmojiconEditText) findViewById(R.id.emojicon_edit_text);
textView = (EmojiconTextView) findViewById(R.id.textView);
emojIcon = new EmojIconActions(this, rootView, emojiconEditText, emojiButton);
emojIcon.ShowEmojIcon();
emojIcon.setKeyboardListener(new EmojIconActions.KeyboardListener() {
#Override
public void onKeyboardOpen() {
Log.e("Keyboard", "open");
}
#Override
public void onKeyboardClose() {
Log.e("Keyboard", "close");
}
});
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String newText = emojiconEditText.getText().toString();
textView.setText(newText);
}
});
}
can you try this may be worked:
emojIcon.setUseSystemEmoji(true);
Perhaps you need you need to convert the Html request to string
Html.fromHtml((String) YOUR_STRING_HERE).toString()
hi i am working on a android project where i am using firebase as back-end and i am building a signup and login form . When ever i sign up the code is working well and . When i try to retrieve it using "signInWithEmailAndPassword i am getting the fallowing error. The email address is badly formatted Firebase`
login Activity
public class LoginActivity extends AppCompatActivity {
private EditText mLoginEmailField;
private EditText mloginPassField;
private Button mLoginbtn;
private Button mNewAccountbtn;
private DatabaseReference mDatabaseRefrence;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
mLoginEmailField = (EditText) findViewById(R.id.loginEmailField);
mloginPassField = (EditText) findViewById(R.id.loginPasswordField);
mLoginbtn = (Button) findViewById(R.id.loginBtn);
mNewAccountbtn = (Button) findViewById(R.id.newAccountbtn);
mDatabaseRefrence = FirebaseDatabase.getInstance().getReference().child("Users");
mNewAccountbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent rigisterIntent = new Intent(LoginActivity.this,RigisterActivity.class);
rigisterIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(rigisterIntent);
}
});
mLoginbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckLogin();
}
});
}
private void CheckLogin() {
String email = mloginPassField.getText().toString().trim();
String pass = mloginPassField.getText().toString().trim();
if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)){
mAuth.signInWithEmailAndPassword(email,pass).addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
CheackUserExsists();
}else{
System.out.println("Sign-in Failed: " + task.getException().getMessage());
Toast.makeText(LoginActivity.this,"Erorr Login",Toast.LENGTH_LONG).show();
}
}
});
}
}
private void CheackUserExsists() {
final String user_id = mAuth.getCurrentUser().getUid();
mDatabaseRefrence.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.hasChild(user_id)){
Intent MainIntent = new Intent(LoginActivity.this,MainActivity.class);
MainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MainIntent);
}else
{
Toast.makeText(LoginActivity.this,"You need to setup your Account.. ",Toast.LENGTH_LONG).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
Rigister Actvity
public class RigisterActivity extends AppCompatActivity {
private EditText mNameField;
private EditText mPassField;
private EditText mEmailField;
private Button mRigisterbtn;
private ProgressDialog mProgres;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rigister);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mAuth = FirebaseAuth.getInstance();
mProgres = new ProgressDialog(this);
mNameField = (EditText) findViewById(R.id.nameField);
mPassField = (EditText) findViewById(R.id.passFiled);
mEmailField = (EditText) findViewById(R.id.emailField);
mRigisterbtn = (Button) findViewById(R.id.rigisterbtn);
mRigisterbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
StartRigister();
}
});
}
private void StartRigister() {
final String name = mNameField.getText().toString().trim();
String pass = mPassField.getText().toString().trim();
String email = mEmailField.getText().toString().trim();
if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(pass) && !TextUtils.isEmpty(email)){
mProgres.setMessage("Signing Up... ");
mProgres.show();
mAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference CurentUser_db = mDatabase.child(user_id);
CurentUser_db.child("name").setValue(name);
CurentUser_db.child("image").setValue("defalut");
mProgres.dismiss();
Intent mainIntent = new Intent(RigisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
}
}
});
}
}
}
I have made sure that i have setup email and password active in the auth section of firebase.
still firebase giving me the following error.
Your code to set email is incorrect. You are setting email to the value of the EditText for password.
In method CheckLogin(), change:
String email = mloginPassField.getText().toString().trim();
to:
String email = mLoginEmailField .getText().toString().trim();
Simply use Edittext named as Email and Password you need not do anything.
the error comes up only if you use plaintext for both...
I faced this problem recently, possible solutions are :
Check the inputType of your EditText Field.
ADD this attribute to your EditText
android:inputType="textEmailAddress"
In Activity class, it should look like if u are using TextInputLayout instead of editText
mDisplayName=(TextInputLayout) findViewById(R.id.reg_name);
mDisplayEmail=(TextInputLayout)findViewById(R.id.reg_email);
mDisplayPassword=(TextInputLayout)findViewById(R.id.reg_password);
String name = mDisplayName.getEditText().getText().toString();
String email = mDisplayEmail.getEditText().getText().toString();
String password = mDisplayPassword.getEditText().getText().toString();`
Remove whitespaces from email text it worked for me. by using trim() method you can remove spaces.
The error popped for me due to my silly action of using "tab" to go to the next text field. Don't use "tab" for it, instead use your mouse to move to the next text field. Worked for me.
What helped me resolve this issue is to put the android:id into the correct place.
If you are using Material design, there are two parts of your text input, the layout and the actual functional part.
If you put the ID into the layout, you'll only be able to access editText property in the activity class, but if you put it in the functional part, you'll be able to access .text or getText() as someone above has stated.
Change
String pass = mloginPassField.getText().toString().trim();
mAuth.signInWithEmailAndPassword(email,pass)
to
String password = mloginPassField.getText().toString().trim();
mAuth.signInWithEmailAndPassword(email,password)
Your code to set email is incorrect.
Perhaps a space was used as the last letter.
final User? user = (await _auth.signInWithEmailAndPassword(
email: _emailController.text.toString().trim(),
password: _passwordController.text,
)).user;[![enter image description here][1]][1]
Let me try this again with better phrasing. I am very new at this; I am trying to pass the value result of checkbox’s to another activity. I have tried it a few different ways without success and I would be grateful for some direction.
I know how to make a “Toast” with the result, that is not what I want it to do. I want the checkbox results will appear in a textview in another activity. If someone could help me out with some hints on how to accomplish that task I would be grateful, I am sorry to bother everyone with such unchallenging questions.
I have read a couple books and watched some tutorials but my skills are still lacking. The books are as repetitive and redundant as the tutorials (buttons and layouts, etc.).
final CheckBox chbxshirleys = (CheckBox)findViewById(R.id.checkboxshirleys);
final CheckBox chbxdianas = (CheckBox)findViewById(R.id.checkboxdianas);
final CheckBox chbxzoila = (CheckBox)findViewById(R.id.checkboxzoila);
final CheckBox chbxsheila = (CheckBox)findViewById(R.id.checkBoxSheila);
final CheckBox chbxrobert = (CheckBox)findViewById(R.id.checkBoxrobert);
final CheckBox chbxsam = (CheckBox)findViewById(R.id.checkBoxsam);
final CheckBox chbxcamren = (CheckBox)findViewById(R.id.checkBoxcamren);
final CheckBox chbxricks = (CheckBox)findViewById(R.id.checkBoxricks);
final Button vendorbutton = (Button)findViewById(R.id.vendorbutton);
vendorbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String vendor ="";
if (chbxshirleys.isChecked())
{
vendor += chbxshirleys.getText();
}
if (chbxdianas.isChecked())
{
vendor += chbxdianas.getText();
}
if (chbxzoila.isChecked())
{
vendor += chbxzoila.getText();
}
if (chbxsheila.isChecked())
{
vendor += chbxsheila.getText();
}
if (chbxrobert.isChecked())
{
vendor += chbxrobert.getText();
}
if (chbxsam.isChecked())
{
vendor += chbxsam.getText();
}
if (chbxcamren.isChecked())
{
vendor += chbxcamren.getText();
}
if (chbxricks.isChecked())
{
vendor += chbxricks.getText();
}
Intent myIntent=new Intent(getApplication(),ApplianceMessage.class);
myIntent.putExtra("chbxshirleys", vendor);
myIntent.putExtra("chbxdianas", vendor);
myIntent.putExtra("chbxzoila", vendor);
myIntent.putExtra("chbxsheila", vendor);
myIntent.putExtra("chbxrobert", vendor);
myIntent.putExtra("chbxsam", vendor);
myIntent.putExtra("chbxcamren", vendor);
myIntent.putExtra("chbxricks", vendor);
startActivity(myIntent);
}
});
}
new activity
public class ApplianceMessage extends Activity {
private TextView tvname = (TextView)findViewById(R.id.tvname);
private EditText etname = (EditText)findViewById(R.id.etname);
private TextView tvcity = (TextView)findViewById(R.id.tvcity);
private EditText etcity = (EditText)findViewById(R.id.etcity);
private TextView tvtime = (TextView)findViewById(R.id.tvtime);
private EditText ettime = (EditText)findViewById(R.id.ettime);
private RadioButton rbutton =(RadioButton)findViewById(R.id.rburgent);
private TextView tvproblem = (TextView)findViewById(R.id.rburgent);
private EditText etproblem = (EditText)findViewById(R.id.etproblem);
private TextView tvvendor = (TextView)findViewById(R.id.vendorlist);
private Button msendbutton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appliance_message);
final Bundle extras = getIntent().getExtras();
extras.getInt("chbxshirleys");
extras.getInt("chbxdianas");
extras.getInt("chbxzoila");
extras.getInt("chbxshiela");
extras.getInt("chbxrobert");
extras.getInt("chbxcamren");
extras.getInt("chbxsam");
extras.getInt("chbxricks");
msendbutton = (Button)findViewById(R.id.sendbutton);
msendbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tvname.setText("Insert Name");
etname.setText("");
tvcity.setText("City Name");
etcity.setText("");
tvtime.setText("Time");
ettime.setText("");
tvproblem.setText("Problem");
etproblem.setText("");
}
});
}
}
In your first activity:
Intent i=new Intent(YourClassName.this,ApplianceMessage.class);
i.putExtra("selected",vendor);
startActivity(i);
In your second Activity:
String selecteditem=getIntent().getExtras().getString("selected");
textview.setText(selecteditem);
You're putting a String Extra in the intent. Just get it by:
getIntent().getStringExtra("chbxshirleys");
....