Skip to content

No getting responded when I press button in app. #1

@Vikas-Konaparthi

Description

@Vikas-Konaparthi

01/04/2019 3:47 pm
I am having many problems so far sir when I enter my phone number and press on send verification button is not responding, this problem occurred to me after I had done with your 10th video. And I can't get any information in Find user it is showing empty screen and more over the user too not get displayed in firebase database.

This is my Find User Activity code.

package com.vikaskonaparthi.***********;

import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.widget.LinearLayout;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

public class FindUserActivity extends AppCompatActivity {

private RecyclerView mUserList;
private RecyclerView.Adapter mUserListAdapter;
private RecyclerView.LayoutManager mUserListLayoutManager;

ArrayList<UserObject> userList,contactList;



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


    contactList = new ArrayList<>();
    userList = new ArrayList<>();
    initializeRecyclerView();
    getContactList();
}
private void getContactList(){

    String ISOPrefix = getCountryISO();
    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    while(phones.moveToNext()){
        String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        String phone = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        phone = phone.replace(" ","");
        phone = phone.replace("-","");
        phone = phone.replace("(","");
        phone = phone.replace(")","");

        if(!String.valueOf(phone.charAt(0)).equals("+"))
            phone = ISOPrefix + phone;
        UserObject mContact = new UserObject("", name,phone);
        contactList.add(mContact);
        getUserDetails(mContact);
    }
}

private void getUserDetails(UserObject mContact) {
    DatabaseReference mUserDB = FirebaseDatabase.getInstance().getReference().child("user");
    Query query = mUserDB.orderByChild("phone").equalTo(mContact.getPhone());
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if(dataSnapshot.exists()){
                String phone = "",
                        name = "";
                for(DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
                    if(childSnapshot.child("phone").getValue()!=null)
                        phone = childSnapshot.child("phone").getValue().toString();

                    if(childSnapshot.child("name").getValue()!=null)
                        name = childSnapshot.child("name").getValue().toString();


                    UserObject mUser = new UserObject(childSnapshot.getKey(), name,phone);
                    if(name.equals(phone))
                        for(UserObject mContactIterator : contactList){
                            if(mContactIterator.getPhone().equals(mUser.getPhone())){
                                mUser.setName(mContactIterator.getName());

                            }
                        }


                    userList.add(mUser);
                    mUserListAdapter.notifyDataSetChanged();
                    return;
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}

private String getCountryISO(){
    String iso = null;

    TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE);
    if(telephonyManager.getNetworkCountryIso()!=null)
        if(!telephonyManager.getNetworkCountryIso().toString().equals(""))
            iso = telephonyManager.getNetworkCountryIso().toString();

    return CountryToPhonePrefix.getPhone(iso);
}
private void initializeRecyclerView() {
    mUserList = findViewById(R.id.userList);
    mUserList.setNestedScrollingEnabled(false);
    mUserList.setHasFixedSize(false);
    mUserListLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayout.VERTICAL, false);
    mUserList.setLayoutManager(mUserListLayoutManager);
    mUserListAdapter = new UserListAdapter(userList);
    mUserList.setAdapter(mUserListAdapter);
}

}

Hope you respond quick .
Thank You sir.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions