FAQ Database Discussion Community


How to fasten a query on Contacts Android

android,android-contacts
In my Android application, an Activity is to display the list of contacts in the user's phone. The issue is that the operation takes about 3 seconds to execute, needless to say this is completely unacceptable. Here is the code I used: private List<Contact> retrieveContacts(ContentResolver contentResolver) { LinkedHashSet<Contact> contactSet =...

Unexpected Token in Fragment

java,android,if-statement,android-fragments,android-contacts
I am trying to embed an if-statement in a fragment to verify if a certain contact has a phone number. If so, I would like to pull the contact data. For some reason, no matter where I try to place an if-statement in the code, I receive an "unexpected token"...

onActivityResult not being Overridden and never reached in a Button.ClickListener

java,android,android-contacts,onactivityresult
I'll start saying I just hope this isn't something so stupid I couldn't notice it, but after hours of researches I haven't found my answer. In my SMSActivity I have created a Button cmdApriRubrica which opens the Contacts default app and then when a Contact is selected returns its data...

Error on picking contacts with no Photo Id/ Display Picture

android,android-contacts
I am accessing a contact's name, number and photo. Everything is working fine but if a contact does not have any photo assigned to it, then the app is throwing an error and force closing. I have the three methods for retrieving name,number and photo and I have used this...

Android - How to get saved contact id

android,contacts,android-contacts,contactscontract
I want to get saved contact id and i used following way to retrieve it but the problem is it's returning the wrong id. public static String addContact(FragmentActivity activity, String displayname, String mobilenumber, String homeemail) { String DisplayName = displayname; String MobileNumber = mobilenumber; String homeemailID = homeemail; int contactID...

how to store value from cursor into string in android

android,android-intent,android-contacts,android-cursor
I'm creating application that can retrieve contact name from number. While Googling, I got this block of code from this post: Getting contact name from number in Android 2.3.4 public static String getContactName(String num, ContentResolver cr) { Uri u = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI Uri.encode(num)); String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME}; Cursor...

Get Contact No From PhoneBook In android

android,android-activity,android-contacts,android-logcat,android-cursor
I'm developing a simple app, in which, when I click on EditText, phone contact will open and when user select a contact, it will be displayed in EditText. I have done it, but the problem is for some contact it display output like this: 05-09 13:39:03.660: D/Actual No--->>>(953): 84 85...

How do you specify URLs for Contact.photos?

cordova,phonegap-plugins,contacts,android-contacts,cordova-plugins
https://github.com/apache/cordova-plugin-contacts#contact Where can I put the image file (eg can I have it on S3, or shipped with the app in the resources), and what is the correct format for the URL? var contact = navigator.contacts.create(); contact.photos = [new ContactField('url', URL, true)]; contact.save() ...

how can I set a ringtone for a specific contact in android in API level 21?

android,android-contacts
I know how to change phone ringtone, also how to get contacts, but how can I set a ringtone for a specific contact? Uri contactData = ContactsContract.Contacts.CONTENT_URI; String contactId = contactData.getLastPathSegment(); Cursor localCursor = managedQuery(contactData, PROJECTION, null, null, null); localCursor.move(120/*CONTACT ID NUMBER*/); String str1 = localCursor.getString(localCursor.getColumnIndexOrThrow("_id")); String str2 = localCursor.getString(localCursor.getColumnIndexOrThrow("display_name"));...

How to open contacts and let user decide if he/she want to create or select one contact

android,android-intent,android-contacts
I'm trying to open contacts and let user decide if he/she want to create or select a contact to use it on my app. I need something like this: Where on the first option the user can add a new contact. I tried the following code: Intent i = new...

Android SQLite adding contacts 'dynamically'

android,sqlite,android-contacts
In my Android app, an Activity performs a query to get the contacts on the phone and stores them into a sqlite database. For now, this is performed only once during the first launch of the Activity because that operation takes about two seconds to execute (which is actually a...

Fetching Phone Number from android is not properly working

android,android-contacts
Using phone.NUMBER for fetching the contacts also return brackets. I am testing it on emulator my Emulator stores contact in (XXX)XXX-XXXX so when I use int phoneIdx = c.getColumnIndex(Phone.NUMBER); int nameid = c.getColumnIndex(Phone.DISPLAY_NAME); number = c.getString(phoneIdx); name = c.getString(nameid); number returns (XXX)XXX-XXXX instead of XXXXXXXXXX...

How to set default image to Android phone contact that has no previous image

android,android-contacts,contactscontract,rawcontacts,rawcontactid
I have a piece of code which updates the an Android contact´s image, the problem is that it doesn't work when the contact has no previous image. I also checked that the contact was from "Phone" account or "*@gmail.com" account. When it already has an image with these accounts I...

How to delete my contact using a dialog?

android,dialog,alert,contacts,android-contacts
What I'm trying here is I want to long press the number that I select and it will pop-up an alert dialog that ask me to delete. If I press Ok it will be deleted. I'm new here, I'm new in android I just want it know if it's possible...

Creating contact with country code in Android

android,android-contentprovider,android-contacts
I have some problem when adding a contact to Content Provider with number prefixed with country code, for example "+48515000111". Adding this kind of number causes that my contact have number like "48515000111" so the "+" character is removed. This is how I add a contact : ArrayList<ContentProviderOperation> ops =...

Unable to identify WhatsApp contacts

android,android-contacts,whatsapp,android-cursor,rawcontactid
I'm trying to write an Android program which can identify if a given contact number is associated with WhatsApp or not. I managed to find out if a particular contact name has WhatsApp account or not. How can I find out which contact corresponding to that contact name has WhatsApp?...

Android contact image placeholder in listview

android,file,uri,contacts,android-contacts
I have an activity with a listview and a custom adapter. Retrieving the contact information and the image is not the problem. I can not display an alternative image if there is not one for the contact. Checking if the URI is NULL does not work for me. I am...

Contact chooser returning null value on selecting a contact

java,android,android-contacts
I am trying to implement contact pciker in android, i am able to launch contact picker in android, but when i select the contact i get back null value, i.e. no number in my textfield. What am i doing wrong ? Here is my code. mainactivity.java package com.example.textmessage; public class...

Unable to get the Contacts in HTC devices

android,android-intent,android-contacts,htc,android-permissions
I'm getting contacts from the ContactPicker from various devices but While trying to fetch contact from HTC devices I'm gettting the below exception : java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/data/719 from pid=8344, uid=10214 requires android.permission.READ_CONTACTS, or grantUriPermission() Permissions that I have given is: android.permission.READ_CONTACTS Below is the code that...

Apache Cordova and Angular - Android - How to take form input and put it into a contact object?

javascript,android,angularjs,cordova,android-contacts
I havent been able to find any good documentation on working with taking HTML form input angularJS. What I want to do, is enter values in my HTML form, use those values to populate a contact object using the cordova contacts plugin, and then save it to my device. Here...

How do implicit joined columns work with Android contacts data?

android,android-contentprovider,contacts,android-contacts,contactscontract
I'm querying the ContactsContract.Data table to find phone records. I get an error when I create a new CursorLoader: java.lang.IllegalArgumentException: Invalid column deleted My code: import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Data; ... String[] projection = { Phone.DELETED, Phone.LOOKUP_KEY, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Data.MIMETYPE, Data.DISPLAY_NAME_PRIMARY }; // "mimetype = ? AND deleted = ?"...

getContext() cannot be resolved in SQLite dB

java,android,android-sqlite,android-contacts
I'm trying to create an SQL database to store local contact information (mainly just phone# (to be verify at a later time) and display name, along with a user-specified boolean. I created a new contactdb class, but I ran into some bumps when trying to use getcontext(). Secondary values for...

Fetching a Single Phone Number from a contact in Contacts Book which is having multiple numbers saved

android,android-contacts
I need to ask a user for a contact number to make a call. On Button Click the User should be directly redirected to Contacts Book and the user can select a Phone Number. Following is the Source Code what I am using now. Button buttonReadContact; TextView textPhone; final int...

how can i get phone number of selected contact

android,android-contacts
c.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Intent i = new Intent(ContactsContract.Contacts.CONTENT_TYPE); Intent i = new Intent(Intent.ACTION_PICK); i.setType(ContactsContract.Contacts.CONTENT_TYPE); startActivityForResult(i, CONTACT_PICKER_RESULT); } }); } public void onActivityResult(int requestCode ,int resultCode ,Intent data) { if ((requestCode == CONTACT_PICKER_RESULT) && (resultCode == RESULT_OK)) { } } This code contains the intent...

How to Add a contact with Data of Birth into device contacts programatically?

android,android-contentprovider,android-contacts
I am using the following code for inserting a contact, but i am unable to find the Date_Of_Birth field to add it. ContentValues values = new ContentValues(); values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); values.put(Phone.NUMBER, "0123456789"); values.put(Phone.TYPE, Phone.TYPE_CUSTOM); values.put(Phone.LABEL, "Ravi"); Uri dataUri = getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); ...

Android Contacts Content Provider sometimes returns empty phone numbers

android,android-contentprovider,android-contacts,android-cursor
Here is the code used to get the contact information : String id = data.getData().getLastPathSegment(); Cursor cursor = getActivity().getContentResolver() .query(ContactsContract.Data.CONTENT_URI, new String[] {ContactsContract.Data.DISPLAY_NAME}, ContactsContract.Data.CONTACT_ID + "=?", new String[]{id}, null); // short circuit if we didn't pick a contact if (cursor.getCount() == 0) { return; } String contact = ""; String...

RuntimeException on Retrieving Contact Data Android

java,android,cursor,android-contacts,runtimeexception
As a part of a simple practice program I am working on, I would like to retrieve data from my cell phone's contacts, specifically the phone number of a selected contact, or all of them, if there is more than one. I begin by launching the Contacts application and allowing...

Android Guaranteed Reference to a Contact

android,android-contacts,android-database
I have an app that needs to maintain persistent references to certain contacts on a device. I used to do this by storing ContactsContract.Contact._ID, but I've recently had issues where the _ID would change and I was no longer able to reference the contact. I switched to using ContactsContract.Contact.LOOKUP_KEY which...