Have such kind of problem: I need to get list of mails form my gmail account. It`s shown in snippet below:
Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
File file = new File("content://gmail-ls/messages/"+accounts[0].name+"/");
if(file.exists())
{
Uri uri = Uri.parse("content://gmail-ls/messages"+accounts[0].name+"/");
cursor = this.getContentResolver().query(uri, null, null, null, null);
}
But it doesn't enter in "if" condition as such path does not exist. With out "if" condition it throws with exception on moment when I assign a cursor by a query with Uri to gmail-ls.
Anyone knows how this problem can be solved? Will appreciate any advice!
Looks like it is not possible any more for third-party apps to read email from Gmail
ref http://productforums.google.com/forum/#!msg/gmail/XD0C4sw9K7U/LpNXxFNnfgc
Related
I tried to read the complete profile information such a (Full name, phone, adresse, mail .... ).
I have searched everywhere for a good example code. I tried many ways (Uri => Cursor) to access the Profile.
At this time I can fetch just the Full name (of the Profile contact), nothing more.
I can fetch data of other contacts using an Intent, sending to the Contacts app, BUT I CAN'T READ THE PROFILE CONTACT (JUST FULL NAME).
I have added the READ_PROFILE permission in the manifest file.
With the following code I get the Full Name (I can also access first and last name separately ):
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = this.getContentResolver().query(uriProfile,
null, null, null, null);
String projection = Profile.DISPLAY_NAME;
String profileName = cursorProfile.getString(cursorProfile.getColumnIndex(projection);
But when I use this the following projection to get Phone Number, it returns an error and the app stops working:
String projection = ContactsContract.CommonDataKinds.Phone.NUMBER
I found a solution using this code:
Get an URI Profile
Crate a cursor pointing to the URI content with null projection. Because for the profile, data are saved differently than a normal contact.
Point the cursor to the wanted data using MIMETYPE.
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = getApplicationContext().getContentResolver().query(uriProfile,
null, null, null, null);
String cursorProfile_MIMIETYPE = cursorProfile.getString(cursorProfile.getColumnIndex("MIMETYPE"));
I can see in LogCat that ActivityManager is reporting something about a particular content provider. I use the following code to try to access that content provider in order to learn more about it:
Cursor cursor = context.getContentResolver().query(uriDSDS, null, null, null, null);
String[] columnNames = cursor.getColumnNames();
Log.d(TAG, "columnNames=" + columnNames.toString());
Unfortunately, after trying to get the cursor, I see the following error in LogCat:
Failed to find provider for __
What's the problem? Why can I not access this provider? Could it be that access is restricted to certain apps? Is there a way to go into ADB or something else to see all of the available content providers on the device?
make sure that you add correct Uri
for example
Uri uriDSDS = Uri.parse(
"content://aaa.aaa/values");
As in the working example below, do check if your uriDSDSis correct.
Cursor people = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null,
null);
// get contact id
while (people.moveToNext()) {
if (people != null) {
int numberFieldColumnIndex = people
.getColumnIndex(PhoneLookup._ID);
String number = people.getString(numberFieldColumnIndex);
contactId.add(number);
}
}
people.close();
Gmail.java link as referred to in one of the questions on SO is broken.
My code is
String account="abc.xyz#gmail.com";
Uri LABELS_URI = Uri.parse("content://gmail-ls/unread/");
Log.d("pavan","label "+LABELS_URI );
Uri ACCOUNT_URI = Uri.withAppendedPath(LABELS_URI, account);
Log.d("pavan","label "+ACCOUNT_URI );
ContentResolver contentResolver= this.getContentResolver();
Log.d("pavan","contentResolver "+contentResolver );
Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);
but the contentResolver line is throwing an error, the logcat says:
cannot find provider info for gmail-ls.
Any ideas how to solve this?
Use the Android Gmail API, if it meets your needs. Otherwise, the Gmail application no longer supports access such as what you are doing.
Is there an accepted/received way of checking to see if a person (phone number) is in the Contact List?
I'm hoping there's something I can call like this:
bool bInContactList = InContactList("1415922353");
It is not as simple as you want but you can query a Contacts content provider for the contact associated with a phone number:
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Cursor c = getContentResolver().query(lookupUri, new String[] {PhoneLookup._ID}, null, null, null);
if (c.getCount() > 0) {
// there is some contact
} else {
// there is no contacts with phoneNumber
}
The application needs android.permission.READ_CONTACTS permission to access contacts data.
You can check Android Developer site for further references about content providers and android.providers package documentation for the list of available standard providers in Android.
I am afraid you did not provide enough information about the language you are talking about. If you use Java -for example- you have a contains method (common to all collections) so, if you want to know if a certain String is contained in a collection you could do it by invoking this method:
boolean found = someCollection.conmtains("1415922353");
I'm reading contact data from ContractContacts, and can lookup TIMES_CONTACTED (which is useful to me), but this field only applies to calls to that contact. I'm also interested in the number of times a contact has been contacted via SMS or email.
Does anyone know if this information is available? I've been searching but haven't come across anything.
For SMS, you'll want to access the inbox located at content://sms/inbox directly and perform a database query to count the number of rows corresponding to the matching contact.
Something like:
String personAddress = addressFromContact();
Uri smsUri = new Uri("content://sms");
if (smsUri != null) {
Cursor smsCursor = getContentResolver().query(smsUri, null, "address=?", new String[] {personAddress}, null);
int smsCount = smsCursor.getCount();
}