私は現在、デバイスのアドレス帳から連絡先を取得しています。私は電子メールを取得することに問題があります。私は試してみて、それは電話番号か数字のどちらかを表示し続けます(私はそれがタイプであると推測しています)。助けてください。メールアドレスAndroidで表示されないアドレス帳
は、ここでは、この問題が解決された場合、私は感謝してください、私のAdressBook.java
package newgbacard.gbacard.com.gbacard.fragments;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import newgbacard.gbacard.com.gbacard.R;
import newgbacard.gbacard.com.gbacard.activities.ContactDetailActivity;
import newgbacard.gbacard.com.gbacard.activities.SettingsActivity;
import newgbacard.gbacard.com.gbacard.adapters.ContactUserAdapter;
import newgbacard.gbacard.com.gbacard.models.Contact;
import newgbacard.gbacard.com.gbacard.utils.Constants;
public class AddressBookFragment2 extends Fragment {
private ArrayList<Contact> selectUsers;
private ListView listView;
private Cursor phoneCursor;
private Cursor emailCursor;
private MenuItem searchMenuItem;
// Pop up
ContentResolver resolver;
SearchView searchView;
ContactUserAdapter adapter;
String email;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment_addressbook, null);
selectUsers = new ArrayList<Contact>();
resolver = getActivity().getContentResolver();
listView = (ListView) view.findViewById(R.id.list);
try {
phoneCursor = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
LoadContact loadContact = new LoadContact();
loadContact.execute();
setHasOptionsMenu(true);
} catch (Exception e){
e.printStackTrace();
}
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_addressbook_fragment, menu);
searchMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) searchMenuItem.getActionView();
searchView.setOnQueryTextListener(listener);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent intent = new Intent(getActivity(), SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
SearchView.OnQueryTextListener listener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// newText is text entered by user to SearchView
adapter.filter(newText);
return false;
}
};
// Load data on background
class LoadContact extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
// Get Contact list from Phone
if (phoneCursor != null) {
Log.e("count", "" + phoneCursor.getCount());
if (phoneCursor.getCount() == 0) {
Toast.makeText(getActivity(), "No contacts in your contact list.", Toast.LENGTH_LONG).show();
}
while (phoneCursor.moveToNext()) {
Bitmap bitmapThumbnail = null;
String id = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
String displayName = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String email = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
String address = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
String imageThumbnail = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI));
try {
if (imageThumbnail != null) {
bitmapThumbnail = MediaStore.Images.Media.getBitmap(resolver, Uri.parse(imageThumbnail));
} else {
// Log.e("No Image Thumb", "--------------");
}
} catch (IOException e) {
e.printStackTrace();
}
Contact contact = new Contact();
contact.setThumb(bitmapThumbnail);
contact.setFirstName(displayName);
contact.setLastName("");
contact.setPhoneNumber(phoneNumber);
contact.setEmail(email);
contact.setAddress(address);
selectUsers.add(contact);
}
}
//phones.close();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter = new ContactUserAdapter(selectUsers, getActivity());
listView.setAdapter(adapter);
// Select item on listclick
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
Contact contact = selectUsers.get(i);
Intent intent = new Intent(getActivity(), ContactDetailActivity.class);
intent.putExtra(Constants.TAG_CONTACT_DETAIL, contact);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
//listView.setFastScrollEnabled(true);
}
}
}
です。
phoneCursor = getActivity().getContentResolver().query(Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
テーブルPhone.CONTENT_URIでのみ電話番号に関連する情報が含まれ、それが含まれていません:ありがとう